我得到一个MSVC 2013内部编译器错误(error C1001
),试图编译一个具有operator*()
成员模板的C ++类,可以通过替换失败选择性地禁用它。
以下是产生此错误的最小代码。请注意,我还定义了一个与get()
完全相同的模板方法operator*()
,但编译得很好。
这是一个合法的MSVC错误还是这个代码有问题?它用gcc编译好(link)。
有谁知道如何解决或解决它?
#include <iostream>
struct Readonly
{
typedef void read;
};
struct ReadWrite
{
typedef void read;
typedef void write;
};
template <typename AccessLevel>
class Wrapper
{
public:
Wrapper(double value)
: _value(value)
{}
template <typename A = AccessLevel, typename = typename A::read>
const double& operator*() const
{
return _value;
}
template <typename A = AccessLevel, typename = typename A::write>
double& operator*()
{
return _value;
}
template <typename A = AccessLevel, typename = typename A::read>
const double& get() const
{
return _value;
}
template <typename A = AccessLevel, typename = typename A::write>
double& get()
{
return _value;
}
protected:
double _value;
};
int main()
{
Wrapper<ReadWrite> wr(88);
Wrapper<Readonly> const_wr(99);
//// uncomment this to get error C1001
//std::cout << "*wr = " << *wr << std::endl;
//std::cout << "*const_wr = " << *const_wr << std::endl;
std::cout << "wr.get() = " << wr.get() << std::endl;
std::cout << "const_wr.get() = " << const_wr.get() << std::endl;
return 0;
}