自己声明了一个类,但是在CPP文件中定义的时候,编译老提示小弟我没有定义这个类,求大神解惑
自己声明了一个类,但是在CPP文件中定义的时候,编译老提示我没有定义这个类,求大神解惑啊
[code=C/C++][/code]
//point.h
#ifdef HEADER_POINT
#define HEADER_POINT
class Point{
protected:
double x,y;
public:
static double PI;
public:
Point(double a=0,double b=0);
double xoffset()const;
double yoffset()const;
double angle()const;
double radius()const;
Point operator+(const Point& d)const;
Point& operator+=(const Point& d);
void moveTo(double a,double b);
friend inline ostream& operator<<(ostream& o,const Point& d){
return o<<'('<<d.x<<','<<d.y<<')'<<'\n';
}
};
#endif
//
//point.cpp
#include "point.h"
#include <iostream>
using namespace std;
#include <cmath>
double Point::PI=3.1415926;
Point::Point(double a,double b):x(a),y(b){}
double Point::xoffset()const{return x;}
double Point::yoffset()const{return y;}
double Point::angle()const{return (180/PI)*atan2(y,x);}
double Point::radius()const{return sqrt(x*x+y*y);}
void Point::moveTo(double a,double b){x=a;y=b;}
Point Point::operator +(const Point& d)const{return Point(x+d.x,y+d.y);}
Point& Point::operator +=(const Point& d){
x+=d.x;
y+=d.y;
return *this;
}
对了我的vs2010,
///错误如下
error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): error C2550: “Point”: 构造函数初始值设定项列表只能在构造函数定义中使用
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): warning C4508: “Point”: 函数应返回一个值;假定“void”返回类型
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(7): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(7): error C2270: “xoffset”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(7): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(8): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(8): error C2270: “yoffset”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(8): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2270: “angle”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2270: “radius”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(11): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(11): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(11): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(12): error C2653: “Point”: 不是类或命名空间名称
[code=C/C++][/code]
//point.h
#ifdef HEADER_POINT
#define HEADER_POINT
class Point{
protected:
double x,y;
public:
static double PI;
public:
Point(double a=0,double b=0);
double xoffset()const;
double yoffset()const;
double angle()const;
double radius()const;
Point operator+(const Point& d)const;
Point& operator+=(const Point& d);
void moveTo(double a,double b);
friend inline ostream& operator<<(ostream& o,const Point& d){
return o<<'('<<d.x<<','<<d.y<<')'<<'\n';
}
};
#endif
//
//point.cpp
#include "point.h"
#include <iostream>
using namespace std;
#include <cmath>
double Point::PI=3.1415926;
Point::Point(double a,double b):x(a),y(b){}
double Point::xoffset()const{return x;}
double Point::yoffset()const{return y;}
double Point::angle()const{return (180/PI)*atan2(y,x);}
double Point::radius()const{return sqrt(x*x+y*y);}
void Point::moveTo(double a,double b){x=a;y=b;}
Point Point::operator +(const Point& d)const{return Point(x+d.x,y+d.y);}
Point& Point::operator +=(const Point& d){
x+=d.x;
y+=d.y;
return *this;
}
对了我的vs2010,
///错误如下
error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): error C2550: “Point”: 构造函数初始值设定项列表只能在构造函数定义中使用
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(6): warning C4508: “Point”: 函数应返回一个值;假定“void”返回类型
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(7): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(7): error C2270: “xoffset”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(7): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(8): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(8): error C2270: “yoffset”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(8): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2270: “angle”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(9): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2270: “radius”: 非成员函数上不允许修饰符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(10): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(11): error C2653: “Point”: 不是类或命名空间名称
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(11): error C2065: “x”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(11): error C2065: “y”: 未声明的标识符
1>f:\程序代码\c++\29继承与组成对象分析\29继承与组成对象分析\point.cpp(12): error C2653: “Point”: 不是类或命名空间名称