At compile time, the code below in clang I have a warning (in vC ++ it works fine):
warning: the explicit specialization of "Helper" within the class is the Microsoft Extension [-Wmicrosoft]
#include <stdio.h>
#include <string>
enum class Car { BMW };
class C
{
static void Method() { puts("inner");}
};
template<typename T>
class BaseClass
{
private:
template<typename V>
struct Helper;
template<>
struct Helper<Car>
{
typedef C InnerType;
static const char* Name() { return "Car"; }
};
typedef Helper<T> Info;
typedef typename Info::InnerType InnerType;
private:
T v;
protected:
BaseClass()
{ }
public:
T Value() const { return v; }
std::string Name() const { return Info::Name(); }
static void Print() { InnerType::Method(); }
};
class MyCar : public BaseClass<Car>
{
public:
MyCar() : BaseClass() {}
};
int main()
{
MyCar a;
printf("%s\n", a.Name().c_str());
}
I tried to move the specialization of the Helper class out BaseClassfor compatibility with the standard:
template<> template<>
struct BaseClass<Car>::Helper<Car>
{
typedef C InnerType;
static const char* Name() { return "Car"; }
};
But now I have a compilation error:
error: implicit template creation undefined "BaseClass :: Helper"
If I delete the line: typedef typename Info::InnerType InnerType;(and the associated use in the function Print), then everything will be fine.
Can this error be fixed? I would like to keep the class Helperas private.
Adamf source
share