| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 825 人关注过本帖
标题:很简单的问题
只看楼主 加入收藏
chenjiang001
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2006-3-21
收藏
 问题点数:0 回复次数:8 
很简单的问题

#include "stdio.h"
#include <iostream.h>

class Location()
{
public:
Location(int xx=0,int yy=0);
Location(Location & p);
~Location();
int GetX(){return X;}
int GetY(){return Y;}
private:
int X,Y;
};
Location::Location(int xx,int yy)
{
X=xx;
Y=yy;
cout<<"constructor Object.\n";
}
Location::~Location()
{
cout<<X<<","<<Y<<"objiect destroyed."<<endl;
}
Location::Location(Location & p)
{
X=p.X;
Y=p.Y;
cout<<"copy constructor called.\n";
}
void f(Location p)
{
cout<<"Function"<<p.GetX()<<","<<p.GetY()<<endl;
}
void main()
{
Location B(1,2);
f(B);
}

这个程序应该没问题吧.怎么通不过编译?
王高手指点!

搜索更多相关主题的帖子: private include Object public return 
2007-01-03 12:42
一二三四五
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:856
专家分:0
注 册:2006-11-13
收藏
得分:0 
using namespace std;
加上这句

hey,di va la
2007-01-03 12:51
chenjiang001
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2006-3-21
收藏
得分:0 

error C2871: 'std' : does not exist or is not a namespace
D:\chenjiang\\gouzao\gouzao.cpp(12) : error C2143: syntax error : missing ';' before 'public'
D:\chenjiang\\gouzao\gouzao.cpp(14) : error C2065: 'p' : undeclared identifier
D:\chenjiang\\gouzao\gouzao.cpp(14) : error C2296: '&' : illegal, left operand has type 'int (__cdecl *)(void)'
D:\chenjiang\\gouzao\gouzao.cpp(14) : error C2660: 'Location' : function does not take 1 parameters
D:\chenjiang\\gouzao\gouzao.cpp(15) : warning C4552: '~' : operator has no effect; expected operator with side-effect
D:\chenjiang\\gouzao\gouzao.cpp(16) : error C2601: 'GetX' : local function definitions are illegal
D:\chenjiang\\gouzao\gouzao.cpp(17) : error C2601: 'GetY' : local function definitions are illegal
D:\chenjiang\gouzao\gouzao.cpp(18) : error C2143: syntax error : missing ';' before 'private'
D:\chenjiang\\gouzao\gouzao.cpp(21) : error C2653: 'Location' : is not a class or namespace name
D:\chenjiang\\gouzao\gouzao.cpp(23) : error C2065: 'X' : undeclared identifier
D:\chenjiang\\gouzao\gouzao.cpp(24) : error C2065: 'Y' : undeclared identifier
D:\chenjiang\\gouzao\gouzao.cpp(26) : warning C4508: 'Location' : function should return a value; 'void' return type assumed
D:\chenjiang\\gouzao\gouzao.cpp(27) : error C2653: 'Location' : is not a class or namespace name
D:\chenjiang\\gouzao\gouzao.cpp(28) : error C2084: function 'int __cdecl Location(void)' already has a body
D:\chenjiang\\gouzao\gouzao.cpp(31) : error C2653: 'Location' : is not a class or namespace name
D:\chenjiang\\gouzao\gouzao.cpp(31) : error C2563: mismatch in formal parameter list
D:\chenjiang\\gouzao\gouzao.cpp(32) : error C2448: '<Unknown>' : function-style initializer appears to be a function definition
D:\chenjiang\\gouzao\gouzao.cpp(37) : error C2146: syntax error : missing ')' before identifier 'p'
D:\chenjiang\\gouzao\gouzao.cpp(37) : error C2182: 'f' : illegal use of type 'void'
D:\chenjiang\\gouzao\gouzao.cpp(37) : error C2440: 'initializing' : cannot convert from '' to 'int'
Context does not allow for disambiguation of overloaded function
D:\chenjiang\\gouzao\gouzao.cpp(37) : error C2059: syntax error : ')'
D:\chenjiang\\gouzao\gouzao.cpp(38) : error C2143: syntax error : missing ';' before '{'
D:\chenjiang\\gouzao\gouzao.cpp(38) : error C2447: missing function header (old-style formal list?)
D:\chenjiang\\gouzao\gouzao.cpp(43) : error C2146: syntax error : missing ';' before identifier 'B'
D:\chenjiang\\gouzao\gouzao.cpp(43) : warning C4551: function call missing argument list
D:\chenjiang\\gouzao\gouzao.cpp(43) : error C2065: 'B' : undeclared identifier
Error executing cl.exe.

gouzao.exe - 24 error(s), 3 warning(s)
加了后还是出现一大队错误。
真不知该怎么改.
望指点


2007-01-03 13:04
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

没这么多吧

[此贴子已经被作者于2007-1-3 13:12:35编辑过]


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-01-03 13:09
chenjiang001
Rank: 1
等 级:新手上路
帖 子:133
专家分:0
注 册:2006-3-21
收藏
得分:0 
我也不知道

2007-01-03 13:16
peswe
Rank: 1
等 级:新手上路
帖 子:197
专家分:0
注 册:2006-11-22
收藏
得分:0 
呵呵,也是新手吧,都会犯同样的错误,我也经常犯呢:
你的类名后面多了个括号,你把他当函数来使用了!~
去掉后就OK了!~

C斗士~~~fighting!!!!
2007-01-03 14:50
pusawl
Rank: 1
等 级:新手上路
帖 子:42
专家分:0
注 册:2006-12-14
收藏
得分:0 
哈哈,有人没看出来~~

2007-01-03 16:52
kai
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:52
帖 子:3450
专家分:59
注 册:2004-4-25
收藏
得分:0 
[CODE]#include <iostream>
using namespace std;

class Location
{
public:
Location(int xx=0,int yy=0);
Location(Location & p);
~Location();
int GetX(){return X;}
int GetY(){return Y;}
private:
int X,Y;
};
Location::Location(int xx,int yy)
{
X=xx;
Y=yy;
cout<<"constructor Object.\n";
}
Location::~Location()
{
cout<<X<<","<<Y<<"objiect destroyed."<<endl;
}
Location::Location(Location & p)
{
X=p.X;
Y=p.Y;
cout<<"copy constructor called.\n";
}
void f(Location p)
{
cout<<"Function"<<p.GetX()<<","<<p.GetY()<<endl;
}

int main()
{
Location B(1,2);
f(B);

return 0;
}

[/CODE]

自由,民主,平等,博爱,进步.
中华民国,我的祖国,中华民国万岁!中华民国加油!
本人自愿加入中国国民党,为人的自由性,独立性和平等性而奋斗!
2007-01-03 17:07
墨岛
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2006-7-25
收藏
得分:0 
class Location()
哪有这个括号,去掉。
#include "stdio.h"
这个也多余,去掉
ok
2007-01-03 18:40
快速回复:很简单的问题
数据加载中...
 
   



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

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