Here is a simplified example:
template
class MyTemplate
{
class Inner {};
Inner met();
};
template
MyTemplate::Inner MyTemplate::met()
{ }
I get the following compilation error:
expected constructor, destructor, or type conversion before 'met'
I use GCC. It seems the compiler doesn't recognize MyTemplate
as a proper class. How can I fix this? I've tried sticking the typename
keyword here and there to no avail. Right now, the only way I can manage to compile this is to inline the method definition in the class declaration, which I would like to avoid.
Answer
Clang reports the following:
error: missing 'typename' prior to dependent type name
'MyTemplate::Inner' MyTemplate::Inner MyTemplate::met()
^~~~~~~~~~~~~~~~~~~~ typename 1 error generated.
And placing typename
in the appropriate place fixes it.
template
class MyTemplate
{
class Inner {};
Inner met();
};
template
typename MyTemplate::Inner MyTemplate::met()
{ }
Did you put typename in the correct location? If so, then this must be a bug in G++.
No comments:
Post a Comment