Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Template argument as template argument

0 views
Skip to first unread message

nw

unread,
Apr 14, 2008, 9:36:06 AM4/14/08
to
Hi All,

Could someone point me in the right direction with this code? If I
change "myclass<_prec>::atype t = 0;" to " myclass<double>::atype t
= 0;" it compiles. Am I not allowed to use a template argument as a
template argument for another class? gcc gives the error:

templateargasarg.cpp:17: error: expected `;' before 't'
templateargasarg.cpp:18: error: 't' was not declared in this scope

Any help appreciated.

#include <iostream>

using namespace std;

template<class _prec=double>
class myclass {
public:

typedef int atype;
};

template<class _prec=double>
class myclass2 {
public:

_prec method() {
myclass<_prec>::atype t = 0;
return t;
}
};

int main() {

myclass2<> m;

}

Victor Bazarov

unread,
Apr 14, 2008, 10:02:47 AM4/14/08
to
nw wrote:
> Could someone point me in the right direction with this code? If I
> change "myclass<_prec>::atype t = 0;" to " myclass<double>::atype t
> = 0;" it compiles. Am I not allowed to use a template argument as a
> template argument for another class? gcc gives the error:
>
> templateargasarg.cpp:17: error: expected `;' before 't'
> templateargasarg.cpp:18: error: 't' was not declared in this scope
>
> Any help appreciated.

Read up on "dependent names".

>
> #include <iostream>
>
> using namespace std;
>
> template<class _prec=double>
> class myclass {
> public:
>
> typedef int atype;
> };
>
> template<class _prec=double>
> class myclass2 {
> public:
>
> _prec method() {
> myclass<_prec>::atype t = 0;

typename myclass<_prec>::atype t = 0;

> return t;
> }
> };
>
> int main() {
>
> myclass2<> m;
>
> }

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


0 new messages