免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3021 | 回复: 2

[C++] ISO C++ forbids declaration of 'setA' with no type [复制链接]

论坛徽章:
0
发表于 2012-10-27 14:51 |显示全部楼层
报错:
  1. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\main.cpp:2: In file included from ..\..\QtProject\test\main.cpp:2:
  2. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\Test.h:24: 错误:ISO C++ forbids declaration of 'setA' with no type
  3. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\Test.h:24: 错误:prototype for 'int A::setA(int)' does not match any in class 'A'
  4. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\Test.h:5: 错误:candidate is: void A::setA(int)
  5. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\Test.h:27: 错误:ISO C++ forbids declaration of 'setB' with no type
  6. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\Test.h:27: 错误:prototype for 'int B::setB(int)' does not match any in class 'B'
  7. E:\project\test-build-desktop-Qt_4_8_1_for_Desktop_-_MinGW__Qt_SDK____\..\..\QtProject\test\Test.h:12: 错误:candidate is: void B::setB(int)
复制代码
Test.h如下:
  1. #ifndef TEST_H
  2. #define TEST_H
  3. class A{
  4. public:
  5.     void setA(int);
  6.     void showA();
  7. private:
  8.     int a;
  9. };
  10. class B{
  11. public:
  12.     void setB(int);
  13.     void showB();
  14. private:
  15.     int b;
  16. };
  17. class C:public A,private B{
  18. public:
  19.     void setC(int,int,int);
  20.     void showC();
  21. private:
  22.     int c;
  23. };
  24. A::setA(int x){
  25.     a=x;
  26. }
  27. B::setB(int x){
  28.     b=x;
  29. }
  30. void C::setC(int x,int y,int z){
  31.     setA(x);
  32.     setB(y);
  33.     c=z;
  34. }
  35. #endif // TEST_H
复制代码
main.cpp
  1. #include <iostream>
  2. #include <Test.h>
  3. using namespace std;

  4. int main(){
  5.     C obj;
  6.     obj.setA(5);
  7.     obj.showA();
  8.     obj.setC(6,7,9);
  9.     obj.showC();
  10.     return 0;
  11. }
复制代码

论坛徽章:
14
巨蟹座
日期:2013-11-19 14:09:4615-16赛季CBA联赛之青岛
日期:2016-07-05 12:36:0515-16赛季CBA联赛之广东
日期:2016-06-29 11:45:542015亚冠之全北现代
日期:2015-07-22 08:09:472015年辞旧岁徽章
日期:2015-03-03 16:54:15巨蟹座
日期:2014-12-29 08:22:29射手座
日期:2014-12-05 08:20:39狮子座
日期:2014-11-05 12:33:52寅虎
日期:2014-08-13 09:01:31巳蛇
日期:2014-06-16 16:29:52技术图书徽章
日期:2014-04-15 08:44:01天蝎座
日期:2014-03-11 13:06:45
发表于 2012-10-27 15:13 |显示全部楼层
void A::setA(int x){
    a=x;
}
void B::setB(int x){
    b=x;
}

论坛徽章:
4
水瓶座
日期:2013-09-06 12:27:30摩羯座
日期:2013-09-28 14:07:46处女座
日期:2013-10-24 14:25:01酉鸡
日期:2014-04-07 11:54:15
发表于 2012-10-28 22:37 |显示全部楼层
顶楼上, 定义函数的时候没有写返回类型.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP