The following snippet does not compile in MSVC C ++ (2015, 2017):
template <typename Type> struct Base : public Type { Base(const Type & type) : Type(type) {} }; struct SomeType { int Type() { return 42; } }; struct Wrong : public Base<SomeType> { Wrong(const SomeType & type) : Base<SomeType>(type) {} }; SomeType some; Wrong wrong(some);
The compiler is confused and interprets a call to the Type constructor with a call to the Type() method of the class I'm trying to get from. The GNU C ++ compiler has no code problems.
Renaming a template argument. Solve the problem in declaring a base class on something else (not in collision with any method of the base class). Adding something like : (typename Type)(type) doesn't help.
Is this an MSVC C ++ compiler error. Any tips to solve these problems?
c ++ visual-c ++
Freemanix
source share