Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
aclass Aと have ステートメントがあるとします:
class A
a1(1); a2; a2(1);
a1(1);
a2; a2(1);
2つのステートメントの違いは何ですか? 最初のステートメントは簡単ですが、ステートメント 2 の横で何が起こっているのでしょうか?
A a1(1);
これは、コンストラクターを引数で呼び出して、a1クラスのインスタンスを作成します。A1
a1
A
1
A a2; a2(1);
これは実際には 2 つのステートメントです。最初の は、 のデフォルト コンストラクターを呼び出して、クラスA a2;のインスタンスを作成します。2 番目のは、パラメータを指定して呼び出します (または が定義されていない場合はエラーを生成します)。a2AAa2(1);A::operator()1Aoperator()
A a2;
a2
a2(1);
A::operator()
operator()