以下の内容はhttps://iww.hateblo.jp/entry/20160623/publicより取得しました。


デフォルトコンストラクタが呼ばれない

#include <iostream>
using namespace std;

class hoge {
public:
    hoge(){ 
        cout << "hello";
    }
    void run(char *text){
        cout << text;
    }
};

class piyo {
public:
    piyo(int a){ 
        cout << a << "world";
    }
    void run(char *text){
        cout << text;
    }
};

int main() {
    hoge a();       // helloが出ない
//  a.run("unko");  // ★aが無いというコンパイルエラー

    hoge b;         // helloが出る
    b.run("unko");  // unkoも出る
    
    piyo c(9);      // 9worldが出る
    c.run("unko");  // unkoも出る

    return 0;
}

()をつけるとデフォルトコンストラクタが呼ばれない。というか、aという変数はつくられない。
よく分からない仕様




以上の内容はhttps://iww.hateblo.jp/entry/20160623/publicより取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14