我有一个执行类的下面程序,该程序填充下面所示的映射
map<string,map<string,vector<StructAbsTypeObject>>>
Run Code Online (Sandbox Code Playgroud)
在这里,我正在创建共享对象并分配它们,它们在第一次检查时有效,但是在第二次检查时,shared_ptr返回null。我需要知道原因。该代码看起来不错,但不知道哪里出了问题。
//Code begins
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <memory>
using namespace std;
class Test {
public:
Test(int i):t(i) {
}
private:
int t;
};
class ConcTypeObject {
public:
ConcTypeObject() {
}
ConcTypeObject(const ConcTypeObject& other) {
m_ptr_Test = other.m_ptr_Test;
}
ConcTypeObject& operator=(const ConcTypeObject& other) {
m_ptr_Test = other.m_ptr_Test;
}
void setTest(shared_ptr<Test> ptr) {
cout << "setTest" << endl;
m_ptr_Test = ptr;
}
shared_ptr<Test> getTest() {
return m_ptr_Test;
}
bool isValid() {
if(m_ptr_Test) {
return true; …Run Code Online (Sandbox Code Playgroud)