C++:成员声明结束时的预期';'

C++: expected ';' at end of member declaration

本文关键字:成员 声明 结束 C++      更新时间:2024-04-28

很抱歉法语和英语混合。。。我得到了预期的[Error]";"在该行的成员声明末尾

public:每月(字符串n,字符串s,int t,int b,double sl,int nc,double tc(::employee(n,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);
}
};

以下是代码的外观。clang格式修复了它。

#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); }
};