#include <cstdio>
class test {
public:
test();
test(int a);
test(int a,int b);
};
test::test() {
puts("test()");
}
test::test(int a) {
puts("test(int a)");
}
test::test(int a,int b) {
puts("test(int a,int b)");
}
int main(void) {
test a();
test b(123);
test c(123,456);
return 0;
}
すなわち、引数が0個のコンストラクタは呼ばれていないということです。
また、
#include <cstdio>
class test {
public:
test();
test(int a);
test(int a,int b);
};
test::test() {
puts("test()");
}
test::test(int a) {
puts("test(int a)");
}
test::test(int a,int b) {
puts("test(int a,int b)");
}
int main(void) {
test a=test();
test b=test(123);
test c=test(123,456);
return 0;
}
なぜ最初の書き方では、引数が0個のコンストラクタは呼ばれないのでしょうか?
[hr]
という質問文を書きながらさらに実験をしたところ、つぎのことがわかりました。
#include <cstdio>
class test {
public:
test();
test(int a);
test(int a,int b);
void mikisin();
};
test::test() {
puts("test()");
}
test::test(int a) {
puts("test(int a)");
}
test::test(int a,int b) {
puts("test(int a,int b)");
}
void test::mikisin() {
puts("Hizikata mikisin");
}
int main(void) {
test a();
test b(123);
test c(123,456);
a.mikisin();
return 0;
}
prog.cpp: In function ‘int main()’:
prog.cpp:31: error: request for member ‘mikisin’ in ‘a’, which is of non-class type ‘test ()()’
すなわち、は何らかの別の型として認識されていると考えられます。
もしかして、これは関数ポインタになっているということでしょうか?
‘test ()()’とは何でしょうか?