- 论坛徽章:
- 0
|
报错:- 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:
- 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
- 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'
- 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)
- 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
- 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'
- 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如下:- #ifndef TEST_H
- #define TEST_H
- class A{
- public:
- void setA(int);
- void showA();
- private:
- int a;
- };
- class B{
- public:
- void setB(int);
- void showB();
- private:
- int b;
- };
- class C:public A,private B{
- public:
- void setC(int,int,int);
- void showC();
- private:
- int c;
- };
- A::setA(int x){
- a=x;
- }
- B::setB(int x){
- b=x;
- }
- void C::setC(int x,int y,int z){
- setA(x);
- setB(y);
- c=z;
- }
- #endif // TEST_H
复制代码 main.cpp- #include <iostream>
- #include <Test.h>
- using namespace std;
- int main(){
- C obj;
- obj.setA(5);
- obj.showA();
- obj.setC(6,7,9);
- obj.showC();
- return 0;
- }
复制代码 |
|