Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > nested template...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9800 of 9984
Post > Topic >>

nested template class instantiation from template function problems

by Jeff Koftinoff <jeff.koftinoff@[EMAIL PROTECTED] > Jul 17, 2008 at 09:29 PM

I'm certain that I'm doing something wrong here, but I'm not sure how
to do it right.

Here is the code and the errors I get by uncommenting the individual
lines.

Similar errors happen from Comeau's tryitout, so I think this is not a
gcc bug.

Can anyone help?

----
#include <iostream>
#include <complex>

template <typename T>
class X
{
public:
   template <size_t N>
   class Y
   {
   public:
     Y()
     {
       T x(12);
       std::cout << "X<T>::Y<" << N << "> created, x= " << x << "\n";
     }
   };
};


void test1()
{
   X<float>::Y<8> a;
   X< std::complex<float> >::Y<8> b;
}

template <typename T>
void test2()
{
   typedef X<T> Z;
//typedef typename Z::Y<2> Z1;  // line 32
//typedef Z::Y<2> Z1;           // line 33
//X<T>::Y<2> z1;                // line 34
//typename X<T>::Y<2> z1;       // line 35
}


int main( int argc, char ** argv )
{
   test1();
   test2< std::complex<float> >();
}

////////////////////////////////////

g++-4.2 (mac os x xcode 3.1)
with only line 32 uncommented:

g++-4.2     t.cpp   -o t
t.cpp: In function 'void test2()':
t.cpp:32: error: non-template 'Y' used as template
t.cpp:32: note: use 'test2()::Z::template Y' to indicate that it is a
template
t.cpp:32: error: declaration does not declare anything
t.cpp: At global scope:
t.cpp:49: error: 'with' does not name a type

//////////////////////////////////////////

with only line 33 uncommented:

g++-4.2     t.cpp   -o t
t.cpp: In function 'void test2()':
t.cpp:33: error: non-template 'Y' used as template
t.cpp:33: note: use 'test2()::Z::template Y' to indicate that it is a
template
t.cpp:33: error: too few template-parameter-lists

//////////////////////////////////////////

with only line 34 uncommented:

g++-4.2     t.cpp   -o t
t.cpp: In function 'void test2()':
t.cpp:34: error: 'z1' was not declared in this scope
t.cpp: In function 'void test2() [with T = std::complex<float>]':
t.cpp:42:   instantiated from here
t.cpp:34: error: dependent-name 'X<T>::Y' is parsed as a non-type, but
instantiation yields a type
t.cpp:34: note: say 'typename X<T>::Y' if a type is meant


//////////////////////////////////////////

with only line 35 uncommented:

g++-4.2     t.cpp   -o t
t.cpp: In function 'void test2()':
t.cpp:35: error: non-template 'Y' used as template
t.cpp:35: note: use 'X<T>::template Y' to indicate that it is a
template
t.cpp:35: error: declaration does not declare anything

//////////////////////////////////////////

  with no lines uncommented, it compiles just fine and runs:

$ ./t
X<T>::Y<8> created, x= 12
X<T>::Y<8> created, x= (12,0)



-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 3 Posts in Topic:
nested template class instantiation from template function probl
Jeff Koftinoff <jeff.k  2008-07-17 21:29:28 
Re: nested template class instantiation from template function
Greg Herlihy <greghe@[  2008-07-17 22:38:42 
Re: nested template class instantiation from template function
Jeff Koftinoff <jeff.k  2008-07-18 00:22:47 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 8:35:20 CDT 2008.