nested class templates compile problem

H

Helge

I have a class nested in a template class and a function in the template
class which returns the nested class type. I get compile error when
compiling with the function definition outside the class definition, but
not inside, and I don't understand why. Can anybody help?

Compiler: gcc 4.1.2

Here is a similiar, but simpler code to illustrate the problem:

#include <iostream>
using namespace std;

template <class T>
class out{
public:
class in{
public:
int a;
in(){};
in(int _a) : a(_a){};
};

out(){};

in func(); //This does not work
// in func(){return in(3);}; //This works
};

template <class T>
out<T>::in out<T>::func(){return in(3);};

int main()
{
out<int> out_obj;
out<int>::in in_obj=out_obj.func();
cout << in_obj.a << endl;
}

________________________________________________________

Output:

test.cpp:21: error: expected constructor, destructor, or type conversion
before ‘out’

helge
 
P

Piyo

Helge said:
template <class T>
out<T>::in out<T>::func(){return in(3);};

The typename problem does it again!

template <class T>
typename out<T>::in out<T>::func(){return in(3);};
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top