class CAppFramework : public IBaseApp
{
public:
CAppFramework(std::initializer_list< CClientApp* > input);
CAppFramework();
~CAppFramework();
void Create() override;
void Release() override;
std::vector< CClientApp* > GetClientApps();
private:
std::vector< CClientApp* > m_ClientApps;
};
當我嘗試將項目添加到m_ClientApps載體是這樣的:
int main()
{
CAppFramework appframework = CAppFramework();
appframework.GetClientApps().push_back(new CTest());
appframework.Create();
appframework.Release();
return 0;
}
它失敗。矢量的大小保持爲0
但是如果我添加項目是這樣的:
int main()
{
CAppFramework appframework = CAppFramework({ new CTest() });
appframework.Create();
appframework.Release();
return 0;
}
該項目得到成功添加。這是爲什麼? 我希望有人能幫助我。
再見,祝你有美好的一天!
'GetClientApps'返回副本的時候,應該返回一個參考。 – nwp