Posted By: nektar | Feb 28th, 2006 @ 8:58 PM
page 1 of 1
Comments: 5 | Views: 5877

Why doesn't the following compile in Visual Studio 2003?
GCC compiles it without any errors.

class Outter
{
public:
// First inner class:
template class Inner1
{
};

// Second Inner class:
class Inner2
{
public:
// Method definition:
Outter* Inner1()
{
}
};
};

The error given is:
Debugger.cpp(16): error C2955: 'Outter::Inner1' : use of class template requires template argument list
And is on this line:
// Method definition:
 Outter* Inner1()
So it seems that the compiler confuses the method definition with the previous class deffinition having the same name (Inner1). But why should it?
I also asked this on the VC forums forums.microsoft.com but I got no satisfactory answer till now.
Note: The online forum software is horrible.
Note2: Where are the old good newsgroups for Visual C++. I can find MS newsgroups for almost anything but not for Visual Studio and the languages. Amaizing!

I'm not really a C++-guy, so I won't try to solve your problems, but I do know the MS newsgroup structure, so:

Visual Studio:
microsoft.public.vsnet.*

Languages:
microsoft.public.dotnet.languages.*

And I agree: The online forum software is horrible. But since you can get at the newsgroup through google groups I don't really care Smiley


megame
megame
(Under destruction...)
template < template-parameter-list > declaration
------

class Outter

{

public:

// First inner class:

template<class T> class Inner1

{

};

// Second Inner class:

class Inner2

{

public:

// Method definition:

Outter* Inner1()

{

}

};

};
-----
Now, I don't know why does GCC allow creation of template without template list, nor if this is a standard, but IMHO VC++ is doing it the right way.
Template requires template parameter list, otherwise it is not a template, just a class and template keyword sould be removed (or does GCC just ignore it?).

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
A quick perusal of the standard tells me that omitting the template parameter list including the < > is only allowed when explicitly instantiating an existing template.

The code posted by the OP is therefore not legal C++, and shouldn't compile.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
It appears to be a bug in VS2003. Apparently it's confusing the Inner1 function name with the Inner1 class name while it shouldn't.

FWIW, the code compiles fine using VS2005, so this bug has been fixed.
page 1 of 1
Comments: 5 | Views: 5877
Microsoft Communities