| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1391 人关注过本帖
标题:C++头文件与CPP文件所包含的声明有什么区别,为什么这个小程序头文件出问题 ...
只看楼主 加入收藏
剑飘香
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2011-9-8
结帖率:0
收藏
 问题点数:0 回复次数:5 
C++头文件与CPP文件所包含的声明有什么区别,为什么这个小程序头文件出问题了
//Point.h

#ifndef Point.h
#define Point.h
class Point{
      double x,y;
      public:
             Point(double a=0,double b=0):x(a),y(b){}
             double yuandian()const;
             double liangdian(const Point& obj)const;
             int getx()const;
             int gety()const;
             void setxy(double a,double b);
             void move(double a,double b);
             };
#endif            
      
//Point.cpp


#include "Point.h"  
#include<math.h>
using namespace std;
             void Point::yuandian()const
             {
                  return sqrt(x*x+y*y);
             }
            
             void Point::liangdian(const Point& obj)const
             {
                  return sqrt(((x-obj.x)*(x-obj.x)+((y-obj.y)*(y-obj.y));
             }
            
             int Point::getx()const
             {
                 return x;
             }
             int Point::gety()const
             {
                 return y;
             }
             void Point::setxy(double a,double b)
             {
                  x=a;
                  y=b;
             }
            
             void Point::move(double a,double b)
             {
                  x=a;
                  y=b;
             }

//main

#include <cstdlib>
#include<math.h>
#include <iostream>
#include "Point.h"  
using namespace std;

int main(int argc, char *argv[])
{
   
    system("PAUSE");
    return EXIT_SUCCESS;
}

[ 本帖最后由 剑飘香 于 2011-12-10 23:15 编辑 ]
搜索更多相关主题的帖子: double public include yuandian 声明 
2011-12-10 23:13
共和国鹰派
Rank: 3Rank: 3
来 自:山东
等 级:论坛游侠
帖 子:37
专家分:119
注 册:2011-10-20
收藏
得分:0 
double yuandian()const;

 void Point::yuandian()const

声明和定义不匹配所以错误
2011-12-11 00:07
lonely_21
Rank: 5Rank: 5
等 级:职业侠客
威 望:3
帖 子:108
专家分:395
注 册:2011-11-13
收藏
得分:0 
#include "tt.h"  
#include<math.h>
#include <iostream>
using namespace std;
double Point::yuandian()const    //返回值有问题
{
    return sqrt(x*x+y*y);
}

double Point::liangdian(const Point& obj)const  //同上
{
    return sqrt((x-obj.x)*(x-obj.x)+((y-obj.y)*(y-obj.y)));
}

int Point::getx()const
{
    return x;
}
int Point::gety()const
{
    return y;
}
void Point::setxy(double a,double b)
{
    x=a;
    y=b;
}

void Point::move(double a,double b)
{
    x=a;
    y=b;
}
   



#ifndef Point_
#define Point_
class Point{
double x,y;
public:
             Point(double a=0.0,double b=0.0):x(a),y(b){}
             double yuandian()const ;
             double liangdian(const Point& obj)const;
             int getx()const;
             int gety()const;
             void setxy(double a,double b);
             void move(double a,double b);
};
#endif            
  
看一下,应该明白为什么错了吧
2011-12-11 00:16
剑飘香
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2011-9-8
收藏
得分:0 
回复 2楼 共和国鹰派
改过了可是还有问题,无法编译,显示头文件编译不通过
2011-12-11 10:11
lonely_21
Rank: 5Rank: 5
等 级:职业侠客
威 望:3
帖 子:108
专家分:395
注 册:2011-11-13
收藏
得分:0 
回复 3楼 lonely_21
好着呀,我试了一下我改的可以通过呀
2011-12-11 21:48
lonely_21
Rank: 5Rank: 5
等 级:职业侠客
威 望:3
帖 子:108
专家分:395
注 册:2011-11-13
收藏
得分:0 
#ifndef Point_ ////这个也改了,你再试试
#define Point_////
class Point{
double x,y;
public:
             Point(double a=0.0,double b=0.0):x(a),y(b){}
             double yuandian()const ;
             double liangdian(const Point& obj)const;
             int getx()const;
             int gety()const;
             void setxy(double a,double b);
             void move(double a,double b);
};
#endif            
2011-12-11 21:52
快速回复:C++头文件与CPP文件所包含的声明有什么区别,为什么这个小程序头文件出 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012504 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved