shared_ptr 데이터 멤버가있는 클래스가 있습니다. 아래는 내가 메인 프로그램에 포함 된 단지 헤더 내 프로그램을 컴파일하려고 예를 들어shared_ptr with map (오류 오류 C2664)
class A {
private:
shared_ptr<map<int, std::string>> _pMap;
A();
public:
A(shared_ptr<map<int, std::string>>);
A(const A& source);
A& operator=A(const A&);
};
A::A(shared_ptr<map<int, std::string>> mapPtr)
: _pMap(new std::shared_ptr<std::map<int, std::string>>()) {
_pMap = mapPtr;
A::A(const A& source) : _pMap(source._p) {}
A& A::operator=(const A& source) {
if (this == &source) {
return *this;
}
_pMap = source._pMap;
return *this;
}
이다, 나는 다음과 같은 오류가 나타납니다
error C2664: 'std::_Ptr_base<_Ty>::_Reset0' :
cannot convert parameter 1 from 'std::shared_ptr<_Ty> *'
to 'std::map<_Kty,_Ty> *
을하지만 내가 뭐하는 거지 어디 확실하지 않다 이. 이것이 일어날 수있는 이유에 대해 누군가 안내해 주시겠습니까?
감사합니다.
'그러나 나는 어디에서이 일을하고 있는지 모르겠다.'그리고 당신은 오류를 복제하는 * 완전한 * 그러나 최소한의 예제를 게시하지 않습니다. 그러나 왜 사용자 정의 할당 연산자와 복사 ctor를 작성하고 있습니까? 기본 클래스는 클래스에 완벽하게 적합합니다. – PaulMcKenzie
나는 문제가'A (const A & source);와'A & operator = (const A & source)'일 수 있다고 생각한다. 이동 생성자와 할당이 필요합니다. –