Why does the following code snippet not compile in Visual C++ 2003 It compiles under GCC, so why not in VC2003. What is wrong with it // Outter class: class Outter { public: // First inner class: template class Inner1 {}; // Second Inner class: class Inner2 { public: // Method definition: Outter* Inner1() {} }; };

Why doesn't the following compile under VC2003?
developer
Sure - well, I assumed that the site had stripped the tags. Why would you use the template keyword and not specify a template, I assume this is indeed an error.
So no compiler accepts this then
ssebring
He's probably using an older version of g++ that didn't catch this syntax error (using the template keyword w/o template parameters).
Brian
Heriberto Menendez
Mozilla did that to me too: nuke the linebreaks. Here it is again (over-compensation courtesy of MSDN Forums.)
class
Outter{
public
: // First inner class: template class Inner1{
};
// Second Inner class: class Inner2{
public: // Method definition:Outter* Inner1()
{
}
};
};
Both VS2005 and GCC 3.4.4 give errors on this code, albeit they are worded differently:
Microsoft:
1>e:\tempprojects\frank8\frank8\frank8.cpp(7) : error C3413: 'Outter::Inner1' : invalid explicit instantiation
1>e:\tempprojects\frank8\frank8\frank8.cpp(8) : error C2946: explicit instantiation; 'Outter::Inner1' is not a template-class specialization
GCC:
frank8.cpp:6: error: expected `<' before "class"
The problem is that
template class Inner1
doesn't make sense since it lacks template parameters. e.g.
template<class T> class Inner1
Brian
JayBhanaut
Hi, Nektar.
Both VS6 and early GCC compilers were quite underpar on C++ conformance, especially with template code. If you are trying to compile code that is incorrect w.r.t. the C++ standard, then your only choice is to fix those errors because you can't force the compiler to accept code with syntax errors. Compilers operate in a world of exactness.
I sympathize with you having to sprinkle typename all over the place. I've been through it myself, and it does seem like an odd thing to have to do. But the C++ standard has added this to deal with problematic ambiguities in code using templates.
It's not clear what you're asking of this forum to help you in your goal of compiling your large code base. If you are confused about a compiler error, could you repost the code (make it readable, please
) along with the error
Thanks,
Brian
newgreen
rickkeller
Yicheng
Could you space it so that it's readable please And what errors do you get
Aluri
Well, it compiles fine under VC2005. And it compiles fine under VC2003, here.
// Method declaration: Outter Inner1(){}
// Method definition: Outter* Inner1()
Those two lines are different, which one is it If I add the *, then it compiles in 2005 and not 2003. So I would guess that this means that it's a bug, fixed in VC2005.
You can use search and replace to find/change the Inner1 method calls to GetInner1, or similar. I thought perhaps adding a parameter to the method might fix it ( and give it a default value ), but it doesn't help. It looks like your options are VC2005, or change the method.
Wes123g
It will probably compile under VC6. VC6 would compile just about anything...
Having a method and class with the same name is obviously able to cause confusion, can't you change it
I think if you check the 'this post contains a code sample' down the bottom, you may keep your tags. As it stands, the forum probably supports using HTML inline, your tags are probably being swallowed by the browser.
Perhaps you could try to post the code again, and if all else fails, press the HTML button to make sure you have ampersandLT; instead of the less than sign, and so on, in your post.