首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

Point.h:6: 异常:return type specification for constructor invalid

2012-11-04 
Point.h:6: 错误:return type specification for constructor invalidPoint.hC/C++ code#ifndef POINT_H#d

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;
}

热点排行