如何看待这里的warning

pan2008 2003-08-22 09:14:51


#include "stdafx.h"

class Person
{
public:
operator=(int nYY)
{
nYear=nYY;
}

OnYear()
{
printf("It is %d years old!\n",nYear);
};
private:
int nYear;

};
/*
Person::OnYear()
{
printf("It is %d years old!\n",nYear);
}*/
int main(int argc, char* argv[])
{
Person son;
son=27;
son.OnYear();

return 0;
}

//////////////////////////////////////////////
Compiling...
T6.cpp
D:\00_Win32 Code\T6\T6.cpp(17) : warning C4183: 'OnYear': member function definition looks like a

ctor, but name does not match enclosing class
Linking...

T6.exe - 0 error(s), 1 warning(s)
...全文
43 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
feixue3000 2003-08-22
  • 打赏
  • 举报
回复
OnYear()不是构造函数,因其名字与类名不相同,但又没有返回值,此外加void
GhostAdz 2003-08-22
  • 打赏
  • 举报
回复
首先成员函数没有返回值
把它加上但是这个函数就重定义了
函数不能定义两次的
比如在一个文件里
写 int i=9;int i;
就错了

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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