使えた。
#include <iostream> using namespace std; class Foo { int i; public: Foo(int i) : i(i) { cout << "constructor: " << i << "\n"; } Foo(const Foo &foo) : i(foo.i) { cout << "copy constructor: " << i << "<-" << foo.i << "\n"; i = foo.i; } int get_i() { return i; } }; int main() { Foo foo1(1), foo2(2); Foo foo3 = foo1; foo2 = foo1; cout << foo1.get_i() << "\n"; cout << foo2.get_i() << "\n"; cout << foo3.get_i() << "\n"; return 0; }
constructor: 1
constructor: 2
copy constructor: 1<-1
1
1
1
追記
普通の関数で初期化子は使えなかった…