【发布时间】:2014-07-23 14:29:35
【问题描述】:
知道为什么 a1 =a2 不起作用但 a2=a1 起作用。智能指针模板中必须有一个函数来进行转换?是哪一个?
#include "stdafx.h"
#include<memory>
class TestClass
{
public:
int a ;
};
typedef std::shared_ptr<TestClass> TestSP;
typedef std::shared_ptr<const TestClass> TestConstSP;
int _tmain(int argc, _TCHAR* argv[])
{
TestSP a1 = TestSP();
TestConstSP a2 = TestConstSP();
//a1 =a2; //error C2440: '<function-style-cast>' : cannot convert from 'const std::shared_ptr<_Ty>' to 'std::shared_ptr<_Ty>'
a2=a1;
return 0;
}
【问题讨论】:
-
this list 中的第二个(仍标记为 #1)。
标签: c++ templates type-conversion smart-pointers