こんにちは、directX を使用して C++ でゲームを作成しています
しかし、私はゲームのコンソール版も持っています ('X' やその他の文字を使用して物事を表します)
次のコードがあります。
Unit::Unit(UnitType u){
ZeroAll(); // function that zeros all variables
this->operator=(fileToUnit(u)); // error making code
}
UnitType は、3 つの値 {Infantry、Alien、Predator} を持つ単純な列挙データ型です。
Operator 関数は次のように定義されます。
Unit operator= (Unit u) { return u; }
fileToUnit は...
Unit fileToUnit(UnitType u);
一時的なユニットを作成して返すだけです。他にどうすればいいのか本当にわかりませんが、クラス全体をコンストラクターから変更する必要があります。
編集:具体的でなくてごめんなさい
私の質問は: 関数の結果に基づいてクラスの値を変更する方法
お気に入り
this = functionReturningSameDataType( DataType ConstructorParameters );
エラーは次のとおりです
Microsoft Visual C++ Runtime Library
Debug Assertion Failed!
Program: C:\Windows\system32\MSVCP110D.dll
File: C:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring
Line: 1143
Expression: invalid null pointer
For Information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.
(Press Retry to Debug the application)