循环执行读取配置,我用 _CrtDumpMemoryLeaks();
老说我有内存泄漏
#include <iostream>
#include <vector>
using namespace std;
class configBase
{
public:
virtual void loadData()=0;
virtual ~configBase(){}
};
class ConfigA:public configBase
{
public:
virtual void loadData()
{
cout << "this configA" << endl;
}
~ConfigA()
{
cout << "~A "<< endl;
}
};
class ConfigB :public configBase
{
public:
virtual void loadData()
{
cout << "this configB" << endl;
}
~ConfigB()
{
cout << "~B" << endl;
}
};
class ConfigC :public configBase
{
public:
virtual void loadData()
{
cout << "this configC" << endl;
}
~ConfigC()
{
cout << "~C" << endl;
}
};
class ConfigManager
{
public:
ConfigManager()
{
ConfigA* a=new ConfigA();
ConfigB* b=new ConfigB();
ConfigC* c=new ConfigC();
configVec.push_back(a);
configVec.push_back(b);
configVec.push_back(c);
}
void showConfig()
{
for (auto con:configVec)
{
con->loadData();
}
}
~ConfigManager()
{
for (auto con : configVec)
{
delete con;
}
}
private:
vector<configBase*> configVec;
};
int main()
{
ConfigManager con;
con.showConfig();
}