我正在使用CRTP来实现一些东西,但在XCode 4.5.2中出现错误。以下代码是仍然复制错误的简化版本。它发生在哪里的方法Api::Enable
被定义并有事情做的事实,有没有参数时Api::Enable
电话this->T::Enable
CRTP error with XCode 4.5.2 - 解析问题,预期表达式
enum Enum
{
FOO,
BAR,
BAZ,
};
template <typename T>
class Api
{
public:
template <Enum E, bool On> void Enable() {static_cast<T *>(this)->Enable<E, On>();}
};
class ApiImpl : public Api<ApiImpl>
{
public:
template <Enum E, bool On> void Enable() {}
};
int main(int argc, const char * argv[])
{
ApiImpl clsApi;
clsApi.Enable<FOO, true>();
return 0;
}
这是在Xcode错误的截图线:http://i.imgur.com/IxEOgQ6.png。无论使用“Apple LLVM编译器4.1”还是“LLVM GCC 4.2”,我都会得到同样的错误。 MSVC Express 2010编译没有错误。
请注意,添加函数参数会导致错误消失。下面编译罚款:
enum Enum
{
FOO,
BAR,
BAZ,
};
template <typename T>
class Api
{
public:
template <Enum E , bool On> void Enable(unsigned int X) {static_cast<T *>(this)->Enable<E, On>(X);}
};
class ApiImpl : public Api<ApiImpl>
{
public:
template <Enum E, bool On> void Enable(unsigned int) {}
};
int main(int argc, const char * argv[])
{
ApiImpl clsApi;
clsApi.Enable<FOO, true>(0);
return 0;
}