Reputation: 2273
I try to build a library which compiles just fine on OSX (clang) and Linux (GCC/Clang). I stumbled upon a template definition which MSVC/Visual Studio 2017 does not understand. I could boil it down to:
#include "stdafx.h"
template<class T>
class Parent {
class Child {
friend class Parent;
public:
Child(const Child &r);
};
};
template<class T>
Parent<T>::Child::Child(const Parent<T>::Child &r) {
*this = r;
}
int main(int argc, char const *argv[]) {
/* code */
return 0;
}
This (still) results in the following error:
1>...consoleapplication1.cpp(13): error C2988: unrecognizable template declaration/definition
1>...consoleapplication1.cpp(13): error C2059: syntax error: '('
1>...consoleapplication1.cpp(13): error C2143: syntax error: missing ';' before '{'
1>...consoleapplication1.cpp(13): error C2447: '{': missing function header (old-style formal list?)
but (still) compiles on OSX with Clang or GCC. stdafx.h
and also main
are not part of the actual library code but have been added to allow using this in a VS Windows command line project.
What do I miss here? Does MSVC have issues with member classes or friend declarations in templates?
Upvotes: 4
Views: 3285
Reputation: 60979
VC++'s problem is the fact that the parameter type isn't qualified by typename
. [temp.res]/7:
[…] within the definition of a member of a class template following the declarator-id, the keyword
typename
is not required when referring to the name of a previously declared member of the class template that declares a type or a class template.
The declarator-id is the first component of the declaration, hence any member type in the parameter clause need not be prefixed by typename
.
Upvotes: 3