Visual studio 2010 C++;:Visual Studio编译器因方法ptr参数上的部分模板专门化而崩溃
我有以下代码,可以使用GCC很好地构建,但不能使用VS2010或2013: 头文件:Visual studio 2010 C++;:Visual Studio编译器因方法ptr参数上的部分模板专门化而崩溃,visual-studio-2010,templates,c++11,metaprogramming,Visual Studio 2010,Templates,C++11,Metaprogramming,我有以下代码,可以使用GCC很好地构建,但不能使用VS2010或2013: 头文件: #pragma once #include <type_traits> namespace utilities { template<typename ValueType, typename ObjectType, ValueType (ObjectType::*BindingMethod)(), typename = void> class Property { public:
#pragma once
#include <type_traits>
namespace utilities {
template<typename ValueType, typename ObjectType, ValueType (ObjectType::*BindingMethod)(), typename = void>
class Property
{
public:
Property(ObjectType& object) : mObject(object)
{
mDirty = true;
}
operator const ValueType&() const
{
if (mDirty)
{
mObject.BindingMethod();
mDirty = false;
}
return mValue;
}
protected:
ObjectType& mObject;
mutable bool mDirty;
ValueType mValue;
};
template<typename ValueType, typename ObjectType, ValueType (ObjectType::*BindingMethod)()>
class Property<ValueType, ObjectType, BindingMethod, typename std::enable_if<BindingMethod==nullptr>::type>
{
public:
Property()
{
}
ValueType& operator=(const ValueType& value)
{
mValue = value;
return mValue;
}
operator const ValueType&() const
{
return mValue;
}
protected:
ValueType mValue;
};
class A
{
public:
A() : p2(*this)
{
}
Property<int, A, nullptr> p1;
int p2Binding()
{
return 0;
}
Property<int, A, &A::p2Binding> p2;
};
void Property_Tests()
{
A a;
//a.p1 = 10;
//int val = a.p1;
}
}
#pragma一次
#包括
命名空间实用程序{
模板
类属性
{
公众:
属性(对象类型和对象):mObject(对象)
{
mdrity=true;
}
运算符常量ValueType&()常量
{
如果(MDARTY)
{
BindingMethod();
mdrity=false;
}
返回mValue;
}
受保护的:
ObjectType&mObject;
可变布尔值;
价值型价值;
};
模板
类属性
{
公众:
财产()
{
}
ValueType和运算符=(常量ValueType和值)
{
mValue=值;
返回mValue;
}
运算符常量ValueType&()常量
{
返回mValue;
}
受保护的:
价值型价值;
};
甲级
{
公众:
A():p2(*这个)
{
}
物业p1;
int p2Binding()
{
返回0;
}
物业p2;
};
void属性_测试()
{
A A;
//a、 p1=10;
//int val=a.p1;
}
}
VS编译器在分析::p1成员的声明时崩溃。
我们的目标是能够在不使用绑定方法的情况下,为属性的特殊情况使用模板专门化来拥有相同的类名
是否有解决此编译器错误的方法
PS:由于我们正在使用的工具和依赖项,我们无法迁移到比2013版本更新的VS studio版本。仍然在VS2015更新1中生成ICE。