C++:成员声明结束时的预期';'
C++: expected ';' at end of member declaration
很抱歉法语和英语混合。。。我得到了预期的[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); }
};
相关文章:
- 使用静态成员声明类时遇到问题
- 错误 C2059:语法错误:从结构成员声明'constant'
- std::d eclare_if 或其他在编译时丢弃成员声明的假设方法
- C++ 成员声明中不允许使用限定名称
- 又一个"未找到成员声明"
- auto f = bind(dist<>,gen) 在成员声明C++失败。未被识别为函数
- C++错误:成员声明末尾的预期“;”
- 静态成员声明 c++11
- 如何将成员声明为指向外部"C"函数的指针?
- C++11 - 将非静态数据成员声明为 'auto'
- 类成员声明的快捷方式
- libclang 获取成员声明
- 将成员声明与enable_if一起使用
- 找不到成员声明
- C++错误:找不到成员声明
- 找不到c++成员声明
- 成员声明顺序在类中如果彼此依赖,则为最优解
- 将struct的成员声明为uint32_t时额外的字节
- 为什么类的大小取决于成员声明的顺序?以及如何
- 是成员声明`decltype(name)name;`在第一个名称引用封闭作用域的本地结构中允许