[求助] error: return type specification for constructor invalid XXX

幽龙魔神 2016-08-29 09:26:12
我在头文件里声明了一个类
#ifndef Ljz_H
#define Ljz_H
class Ljz
{
public:
QString YS;
void Ljz();
};
#endif

我在编译的时候提示:
error: return type specification for constructor invalid
void Ljz();
^
...全文
1490 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
paschen 2016-08-30
  • 打赏
  • 举报
回复
void Ljz(); 改成 Ljz(); 构造函数不用返回类型
小灸舞 2016-08-30
  • 打赏
  • 举报
回复
构造函数不需要返回值类型。
C++标准中也没有说原因,但有这样一段话:
No return type (not even void) shall be specified for a constructor. A return statement in the body of a
constructor shall not specify a return value. The address of a constructor shall not be taken.
kongl123 2016-08-29
  • 打赏
  • 举报
回复
知道构造函数吗?构造函数不能有返回类型, void也是返回类型.把void去掉

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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