No default constructor exists for class error

前端 未结 3 741
盖世英雄少女心
盖世英雄少女心 2021-01-13 16:55

Some simple code:

class Thing {
public:
    int num;
    Thing(int num) { 
        this->num = num; 
    }
};

class Stuff {
public:
    Thing thing;  //          


        
3条回答
  •  忘掉有多难
    2021-01-13 17:50

    Initialize thing member in Stuff with initializer list:

    class Stuff {
    public:
        Thing thing;  // an instance of thing is declared here but it cannot construct it
        Stuff(Thing thing): thing(thing) { }
    };
    

提交回复
热议问题