テストプログラムが添付されています。質問:
次のように宣言すると、オブジェクトは作成されず、デフォルトのコンストラクターは呼び出されません。「grCell c3();」// 悪い
ただし、このように宣言しても問題ありません。オブジェクトが作成され、そのコンストラクターが呼び出されます。「grCell c1;」// 良い
「grCell c3()」と「grCell c1」の違いは何ですか?
ありがとう!
トッド
// - - 始める - - - -
#include <iostream>
#include <cstdio>
typedef unsigned int uint;
using namespace std;
//
class grCell {
public:
grCell() { printf("HERE_0\n"); };
grCell(int i) { printf("HERE_1\n"); };
~grCell() {};
void setX(int x) { _x = x; }
//
//
private:
int _x:22;
};
int main()
{
grCell c1; // good
c1.setX(100);
grCell c3(); // bad
c3.setX(100);
grCell c2(5);
c2.setX(10);
}
// - - - 終わり - - -