我有一个严重的问题,我使用默认构造函数来初始化对象,并使用带有参数的构造函数来复制 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();
}
我希望在程序结束时调用析构函数,而不是在复制两个对象时调用。我尝试重载赋值运算符和复制构造函数,但这对我没有帮助。有没有办法做到这一点?