2012-04-02 95 views
1

我得到了编译器错误:错误C2439:成员无法初始化

template<class _Other1, 
     class _Other2> 
     _Pair_base(_Other1&& _Val1, _Other2&& _Val2) 
     : first(_STD forward<_Other1>(_Val1)), 
      second(_STD forward<_Other2>(_Val2)) 
     { 
     } 

    _Ty1 first; 
    _Ty2 second;  
    }; 

error C2440: 'initializing' : cannot convert from 'int' to 'const PP_PropertyType 
error C2439: 'std::_Pair_base<_Ty1,_Ty2>::second' : member could not be initialized 

我不知道,如果这部分代码就足够了...你有什么建议,我该怎么办?

感谢所有帮助

+2

不,你没有收到标准库内部的编译器错误。而且错误甚至会说出什么是错误的以及在哪里(如果您阅读的内容更多,您会注意到如何使用模板的代码指针)。 – 2012-04-02 16:08:15

回答

1

您正在尝试初始化是这样的:

pair<SomeType, PP_PropertyType> x(foo, 1234); 

,它不能第二个参数(1234)从int转换为PP_PropertyType。

问题出现在std :: pair的基类中的标准库错误中,但是它是在您的代码中引起的。