我有一個嚴重的問題,我使用默認的構造函數來初始化對象和一個帶參數的構造函數來複制DirectX接口。爲什麼複製時調用析構函數?
SpriteBatch spriteBatch; //Creating an Object to SpriteBatch Class
//This Function Gets Called when Device is Created with Parameter to Device
void LoadContent(GraphicDevice graphicDevice)
{
/*Here is the Problem, When it Assigns to the Object it creates a Temp Object and
Destructor gets called where I free everything, I can't use the GraphicDevice after
this.*/
spriteBatch = SpriteBatch(graphicDevice);
}
//SpriteBatch Class
class SpriteBatch
{
GraphicDevice graphicDevice;
public:
SpriteBatch();
SpriteBatch(GraphicDevice graphicDevice);
~SpriteBatch();
}
SpriteBatch::SpriteBatch()
{
}
SpriteBatch::SpriteBatch(GraphicDevice graphicDevice)
{
this->graphicDevice = graphicDevice;
}
SpriteBatch::~SpriteBatch()
{
graphicDevice-Release();
}
我希望在程序結束時調用析構函數,而不是在複製兩個對象時調用析構函數。 我試圖重載賦值運算符和複製構造函數,但沒有幫助我。 有沒有辦法做到這一點?
這是如何複製對象的作品。它的確如此簡單 – 2013-02-24 04:28:04
如何在複製時不想讓析構函數調用? – user2028359 2013-02-24 04:30:21