Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ VS2010 C++;成员模板函数专门化错误_C++_Visual Studio 2010_Templates_Specialization - Fatal编程技术网

C++ VS2010 C++;成员模板函数专门化错误

C++ VS2010 C++;成员模板函数专门化错误,c++,visual-studio-2010,templates,specialization,C++,Visual Studio 2010,Templates,Specialization,我有以下(最小化)代码,在VC2005中有效,但在2010年不再有效 template <typename TDataType> class TSpecWrapper { public: typedef typename TDataType::parent_type index_type; public: template <bool THasTriangles> void Spec(index_type& io_ind

我有以下(最小化)代码,在VC2005中有效,但在2010年不再有效

template <typename TDataType>
class TSpecWrapper
  { 
  public:
    typedef typename TDataType::parent_type index_type;


  public:

    template <bool THasTriangles>
    void Spec(index_type& io_index)
      { std::cout << "False version" << std::endl; }

    template <>
    void Spec<true>(index_type& io_index)
      { std::cout << "True version" << std::endl; }
  };
模板
类TSpecWrapper
{ 
公众:
typedef typename TDataType::父类型索引类型;
公众:
模板
无效规范(索引类型和io索引)

{STD::CUT< P>这是根据C++标准的18。 在类模板或出现的成员模板的成员的显式专门化声明中 在名称空间范围内,成员模板及其某些封闭类模板可能未被专门化, 除非声明不应显式专门化类成员模板(如果其包含类) 模板也没有明确专门化

如果没有专门化
TDataType

解决方法,则不允许专门化
Spec

template <bool v> struct Bool2Type { static const bool value = v; }; 

template <typename TDataType> 
class TSpecWrapper 
{  
public: 
    typedef typename TDataType::parent_type index_type; 


public: 
    template <bool THasTriangles> 
    void Spec(index_type& io_index) 
    { 
        return SpecHelp(io_index, Bool2Type<THasTriangles>());
    } 

private:
    void SpecHelp(index_type& io_index, Bool2Type<false>) 
    { std::cout << "False version" << std::endl; } 

    void SpecHelp(index_type& io_index, Bool2Type<true>) 
    { std::cout << "True version" << std::endl; } 

}; 
template struct Bool2Type{static const bool value=v;};
模板
类TSpecWrapper
{  
公众:
typedef typename TDataType::父类型索引类型;
公众:
模板
无效规范(索引类型和io索引)
{ 
返回SpecHelp(io_索引,Bool2Type());
} 
私人:
void SpecHelp(索引类型&io索引,Bool2Type)

{std::cout您为
TDataType
参数传递的类型是什么?有一个
index\u type
index
参数,这是一个打字错误吗?index/index\u type的可能重复确实是一个打字错误(复制错误;-))事实上,通过阅读回答,似乎VS2005非常自由,2010稍微不那么自由,但仍然比标准允许的更自由。所以我猜这个问题在某种程度上是重复的(至少这个问题的答案也包括我的)