重複の可能性:
コンストラクター初期化子リストによる最適化
OK、ここに私のジレンマがあります: クラスがあり、いくつかのコンストラクターがあり、それらが何度も呼び出されるとします (1 秒あたり数億回、速度が重要です)。
どの方法が好ましいですか?(全然違いますか?)
方法 A:
// Prototype
class MyClass
{
public:
// Constructor
MyClass (int x, int y, int z) : X(x), Y(y), Z(z) {}
// Variables
int X,Y,Z;
};
方法 B:
// Prototype
class MyClass
{
public:
// Constructor
MyClass (int x, int y, int z);
// Variables
int X,Y,Z;
};
// Implementation
MyClass::MyClass(int x,int y,int z)
{
this->X=x;
this->Y=y;
this->Z=z;
}