小编use*_*097的帖子

我无法弄清楚C++语法错误"预期`;' 在'{'标记之前

我有这个简单的代码,并收到语法错误:

file.cc:67: error: expected `;' before ‘{’ token
file.cc:73: error: expected primary-expression before ‘(’ token
file.cc:73: error: expected primary-expression before ‘n’
file.cc:73: error: expected `;' before ‘{’ token
Run Code Online (Sandbox Code Playgroud)

我把星星放在67和73的线条周围,它们是班级的构造者.我是C++的新手,无法找到语法问题.这是我第一次制作构造函数.

int main() {

  class Patient {
    private: // default is private but stating explicitly here for learning purposes
        std::string name; //object
        int height; //object
        int weight; //object
    public:
        Patient(); //constructor
        Patient(std::string); //constructor

        void set_name (std::string n) {name=n;} //fn
        void set_height (int h) {if (height>0){height=h;} else {height=0;}} //fn
        void set_weight (int w) …
Run Code Online (Sandbox Code Playgroud)

c++ syntax constructor

3
推荐指数
1
解决办法
2201
查看次数

标签 统计

c++ ×1

constructor ×1

syntax ×1