类的声明中方法的花括号后面到底要不要分号,书上有的写有的没写。

u010179812 2014-07-26 09:42:28
如题:

#ifndef TABLE_H
#define TABLE_H
#include <string>
using namespace std;

class table
{
private:
string firstname;
string lastname;
bool hasTable;
public:
table(const string &fn = "none", const string &la = "none", bool ht = false);
void show()const;
bool HasTable()const{return hasTable;}; //此处加了分号?

};

class copy_talbe: public table
{
private:
int rating;
public:
copy_table(int r=0, const string &fn="none", const string &ln="none", bool ht = false);
copy_table(int r, table &p);
int get_rating()const{return rating} //此处没有加分号?

};
...全文
601 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
我看你有戏 2014-07-26
  • 打赏
  • 举报
回复
IDE不是有通过图形界面创建一个类吗,用那个创建好了啊,何必纠结
乐百川 2014-07-26
  • 打赏
  • 举报
回复
不用吧,函数定义最后不用加括号吧,声明才需要加
勤奋的小游侠 2014-07-26
  • 打赏
  • 举报
回复
引用 5 楼 u013171165 的回复:
实测有的IDE不加分号不行,所以,加上吧!免得换个环境就出错。
花括号后面不用吧?你试的那个IDE?我试一下。
The_Third_Wave 2014-07-26
  • 打赏
  • 举报
回复
实测有的IDE不加分号不行,所以,加上吧!免得换个环境就出错。
taodm 2014-07-26
  • 打赏
  • 举报
回复
C、C++允许在很多地方有多余的; 结贴吧。
taodm 2014-07-26
  • 打赏
  • 举报
回复
C、C++允许在很多地方有多余的; 结贴吧。
u010179812 2014-07-26
  • 打赏
  • 举报
回复
int get_rating()const{return rating;}
括号内掉了一个分号
brookmill 2014-07-26
  • 打赏
  • 举报
回复
不用分号。不过写了分号也不会出错。

64,649

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧