Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++:应为“;”在成员声明末尾_C++ - Fatal编程技术网

C++:应为“;”在成员声明末尾

C++:应为“;”在成员声明末尾,c++,C++,抱歉法语和英语混音。。。 我得到了预期的[错误];'在此行的成员声明末尾 public:monthlystring n,string s,int t,int b,double sl,int nc,double tc::employeen,s,t,b 发现于 #include <iostream> #include <string> using namespace std; class employee {protected: string name;

抱歉法语和英语混音。。。 我得到了预期的[错误];'在此行的成员声明末尾

public:monthlystring n,string s,int t,int b,double sl,int nc,double tc::employeen,s,t,b

发现于

#include <iostream>
#include <string>
using namespace std;


class employee {protected: string name;
                        string surname;
                        int tel;
                        int nbureau;
                public:  employee(string n,string s,int t,int b){
                    name=n;surname=s;tel=t;nbureau=b;
                }
                void affich(){
                    cout<<"nom"<<name<<"\nprenom"<<surname<<"\nnumero tel"<<tel<<"\nnumero bureau"<<nbureau;
                }
                };
class monthly: public employee {private:double salary; 
                                        int nbc;
                                        double tcom;
                                public: monthly(string n,string s,int t,int b,double sl,int nc,double tc)::employee(n,s,t,b){
                                    salary=sl;nbc=nc;tcom=tc;
                                }
                                void affich(){
                                    cout<<"nom"<<employee.name<<"\nprenom"<<employee.surname<<"\nnumero tel"<<employee.tel<<"\nnumero bureau"<<employee.nbureau<<"\nsalaire"<<salary<<"\nnombre de commissions"<<nbc<<"\ntaux de commission"<<tc;
                                }
                                double salary(){
                                    return salary+(nbc*tcom);
                                }
};

下面是代码的外观。叮当声把它修好了

#include <iostream>
#include <string>
using namespace std;

class employee {
protected:
  string name;
  string surname;
  int tel;
  int nbureau;

public:
  employee(string n, string s, int t, int b) {
    name = n;
    surname = s;
    tel = t;
    nbureau = b;
  }
  void affich() {
    cout << "nom" << name << "\nprenom" << surname << "\nnumero tel" << tel
         << "\nnumero bureau" << nbureau;
  }
};
class monthly : public employee {
private:
  double salary;
  int nbc;
  double tcom;

public:
  monthly(string n, string s, int t, int b, double sl, int nc,
          double tc)::employee(n, s, t, b) {
    salary = sl;
    nbc = nc;
    tcom = tc;
  }
  void affich() {
    cout << "nom" << employee.name << "\nprenom" << employee.surname
         << "\nnumero tel" << employee.tel << "\nnumero bureau"
         << employee.nbureau << "\nsalaire" << salary
         << "\nnombre de commissions" << nbc << "\ntaux de commission" << tc;
  }
  double salary() { return salary + (nbc * tcom); }
};
这是一个修正了语法的版本:

#include <iostream>
#include <string>
using namespace std;

class employee {
protected:
  string name;
  string surname;
  int tel;
  int nbureau;

public:
  employee(string n, string s, int t, int b)
      : name(n), surname(s), tel(t), nbureau(b) {}
  void affich() {
    cout << "nom" << name << "\nprenom" << surname << "\nnumero tel" << tel
         << "\nnumero bureau" << nbureau;
  }
};
class monthly : public employee {
private:
  double salary;
  int nbc;
  double tcom;

public:
  monthly(string n, string s, int t, int b, double sl, int nc, double tc)
      : employee(n, s, t, b), salary(sl), nbc(nc), tcom(tc) {}
  void affich() {
    cout << "nom" << name << "\nprenom" << surname << "\nnumero tel" << tel
         << "\nnumero bureau" << nbureau << "\nsalaire" << salary
         << "\nnombre de commissions" << nbc << "\ntaux de commission" << tcom;
  }
  double get_salary() { return salary + (nbc * tcom); }
};

对于成员初始化列表,应该使用:而不是::。你的程序有更多问题。你的格式很奇怪。您可能需要手动或在编辑器中查看使用“铿锵格式”。@MikeCAT谢谢您是的,我正在逐个查看它们在每行代码中打印任何内容,并检查代码的中断位置。您不能编辑问题吗?我的意思是这并不是真正的回答问题。