By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,089 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

nested class templates compile problem

P: n/a
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<intout_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
Feb 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Helge wrote:
>
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);};
Feb 22 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.