【发布时间】:2014-10-08 20:14:15
【问题描述】:
我正在使用 CRTP 来实现某些东西,但在 XCode 4.5.2 中遇到了一个错误。以下代码是仍然复制错误的简化版本。它发生在定义方法Api::Enable的那一行,与Api::Enable调用this->T::Enable时没有参数的事实有关
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;
}
【问题讨论】:
标签: c++ xcode templates clang xcode4.5