473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

nested class templates compile problem

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
1 1344
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alexander Stippler | last post by:
Hi what's wrong about the following code? It does not compile. template <typename T> class A { public: class B; };
2
by: Michael Stembera | last post by:
I would like to use default parameters in nested templates but MS VC++ 7.1 chokes on it. Does anyone know how to fix the simple example below or if indeed it is possible? template <int N=7>...
3
by: Andriy Shnyr | last post by:
Let us consider the following nested templates case: template<typename T> class Outer{ public: template<typename U> class Inner{ public:
6
by: Roger Leigh | last post by:
I've written a fixed-precision class, "numeric". This stores the number of decimal places as a template parameter. I've overloaded all of the normal numerical operators (an example): ...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
2
by: Joseph Geretz | last post by:
When I create a Form, the VB IDE creates the following files in the following hierarchy: Form1.cs Form1.Designer.cs Form1.resx Both Form1.cs and Form1.Designer.cs are partial implementations...
3
by: CrazyAtlantaGuy | last post by:
I am working on creating an XSLT that transforms Html into an XML format that can be imported into Framemaker. The challenge, it turns out, is correctly transforming the flat html header tags...
9
by: stephen.diverdi | last post by:
Can anyone lend a hand on getting this particular template specialization working? I've been trying to compile with g++ 4.1 and VS 2005. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.