读书人

Point.h:6: 异常:return type specifi

发布时间: 2012-11-04 10:42:42 作者: rapoo

Point.h:6: 错误:return type specification for constructor invalid
Point.h

C/C++ code
#ifndef POINT_H#define POINT_Hclass Point{public:    void Point(float xx=0,float yy=0)    {        x=xx;        y=yy;    }    void Move(float xOff,float yOff){        x+=xOff;        y+=yOff;    }    float getX(){return x;}    float getY(){return y;}private:    float x,y;};class Rectangle:public Point{public:    void initR(float x,float y,float w,float h){        Point(x,y);        W=w;        H=h;    }    float getH(){return H;}    float getW(){return W;}private:    float W,H;};#endif // POINT_H


main.cpp
C/C++ code
#include <iostream>#include <Point.h>using namespace std;int main(){    Rectangle rect;    rect.initR(2,30,20,10);    rect.Move(3,2);    cout<<rect.getX()<<','       <<rect.getY()<<','      <<rect.getH()<<','        <<rect.getW()<<endl;    return 0;}


错误:
C/C++ code
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\Point.h:6: 错误:return type specification for constructor invalid


[解决办法]
class Point
{
public:
Point(float xx=0,float yy=0) // 构造函数没有返回值
{
x=xx;
y=yy;
}

读书人网 >C++

热点推荐