| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 746 人关注过本帖
标题:代码全对,为什么编译出错?
只看楼主 加入收藏
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
结帖率:71.43%
收藏
 问题点数:0 回复次数:5 
代码全对,为什么编译出错?
Point.h文件:
# ifndef POINT_H
# define POINT_H
class Point{
   int x,y;
public:
   Point(int a,int b);
   void SetPoint(int a,int b);
   int GetX();
   int GetY();
   void Print();
}
# endif
Circle.h文件
# ifndef CIRCLE_E
# define CIRCLE_E
# include<iostream>
using namespace std;
# include"Point.h"

class Circle:public Point{
    double radius;
public:
    Circle(int a,int b, double r);
    void SetRadius(double r);
    double GetRadius();
    double Area();
    void Print();
};
# endif
Point.cpp文件
# include<iostream>
using namespace std;
# include"Point.h"
Point::Point(int a,int b){
    Point::SetPoint(a,b);
}
void Point::SetPoint(int a,int b){
    Point::x=a;
    Point::y=b;
}
void Point::Print(){
    cout<<"["<<x<<","<<y<<"]";
}
Circle.cpp文件
# include<iostream>
# include"Circle.h"
using namespace std;

Circle::Circle(int a,int b,double r):Point(a,b){
    Circle::SetRadius(r);
}
void Circle::SetRadius(double r){
    radius=(r>=0 ? r:0);
}
double Circle::GetRadius(){
    return radius;
}
double Circle::Area(){
    return 3.14159*radius*radius;
}
void Circle::Print(){
    cout<<"Center = ";
    Point::Print();
    cout<<";Radius = "<<radius<<endl;
}
CircleDemo.cpp文件
# include<iostream>
# include"Circle.h"
using namespace std;

Circle::Circle(int a,int b,double r):Point(a,b){
    Circle::SetRadius(r);
}
void Circle::SetRadius(double r){
    radius=(r>=0 ? r:0);
}
double Circle::GetRadius(){
    return radius;
}
double Circle::Area(){
    return 3.14159*radius*radius;
}
void Circle::Print(){
    cout<<"Center = ";
    Point::Print();
    cout<<";Radius = "<<radius<<endl;
}
在编译的时候出现了如下错误:
--------------------Configuration: PointCircle - Win32 Debug--------------------
Compiling...
CircleDemo.cpp
f:\vc++\vc++程序\myobject\pointcircle\circle.h(4) : error C2143: syntax error : missing ';' before 'using'
F:\vc++\vc++程序\MyObject\PointCircle\CircleDemo.cpp(8) : error C2661: 'Circle::Circle' : no overloaded function takes 4 parameters
执行 cl.exe 时出错.

CircleDemo.obj - 1 error(s), 0 warning(s)
这是我从课本上写下来的,怎么会这样呢?
搜索更多相关主题的帖子: 代码 编译 
2009-10-31 10:08
flyingcloude
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:6
帖 子:598
专家分:1512
注 册:2008-1-13
收藏
得分:0 
# ifndef POINT_H
# define POINT_H
class Point{
   int x,y;
public:
   Point(int a,int b);
   void SetPoint(int a,int b);
   int GetX();
   int GetY();
   void Print();
};
# endif



你能学会你想学会的任何东西,这不是你能不能学会的问题,而是你想不想学的问题
2009-10-31 10:17
魔鬼之子
Rank: 1
来 自:地狱之都
等 级:新手上路
帖 子:100
专家分:0
注 册:2007-9-22
收藏
得分:0 
回复 2楼 flyingcloude
多谢指教

只有仇恨才是永恒的
2009-10-31 10:38
jekdu
Rank: 1
来 自:北京
等 级:新手上路
帖 子:7
专家分:2
注 册:2009-10-31
收藏
得分:0 
一定要注意格式哦!
2009-10-31 23:49
pywepe
Rank: 6Rank: 6
等 级:侠之大者
威 望:4
帖 子:296
专家分:483
注 册:2009-4-5
收藏
得分:0 
全对吗?

明明有错 还有全对

java群
62635216
欢迎加入
2009-11-01 09:50
pywepe
Rank: 6Rank: 6
等 级:侠之大者
威 望:4
帖 子:296
专家分:483
注 册:2009-4-5
收藏
得分:0 
明明就有错 还说全对

java群
62635216
欢迎加入
2009-11-01 19:57
快速回复:代码全对,为什么编译出错?
数据加载中...
 
   



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

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