| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 687 人关注过本帖
标题:[求助]请教菜鸟问题!
取消只看楼主 加入收藏
yylcel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2005-12-10
收藏
 问题点数:0 回复次数:4 
[求助]请教菜鸟问题!

#include<iostream>
#include<string>
using namespace std;
class String
{
public:
String(){p=NULL;}
String(char *str);
void display();
friend bool operator>(String &string1,String &string2);
private:
char *p;
};
String::String(char *str)
{
p=str;
}
void String::display()
{
cout<<p;
}
bool operator>(String &string1,String &string2)
{
if(strcmp(string1.p,string2.p)>0)
return false;
else return true;
}
int main()
{
String string1("hello!"),string2("book!");
cout<<(string1>string2)<<endl;
return 0;
}
--------------------Configuration: vetor1 - Win32 Debug--------------------
Compiling...
vetor1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(24) : error C2248: 'p' : cannot access private member declared in class 'String'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(12) : see declaration of 'p'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(24) : error C2248: 'p' : cannot access private member declared in class 'String'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(12) : see declaration of 'p'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(31) : error C2593: 'operator >' is ambiguous
Error executing cl.exe.

vetor1.exe - 3 error(s), 0 warning(s)

搜索更多相关主题的帖子: private display include public friend 
2006-03-30 21:52
yylcel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2005-12-10
收藏
得分:0 
晕呐没人...自己顶了~~~~急!!!!!!!!!!!
2006-03-30 22:27
yylcel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2005-12-10
收藏
得分:0 

--------------------Configuration: vetor1 - Win32 Debug--------------------
Compiling...
vetor1.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(10) : error C2805: binary 'operator >' has too few parameters
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(23) : error C2805: binary 'operator >' has too few parameters
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(24) : error C2065: 'p' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(24) : error C2248: 'p' : cannot access private member declared in class 'String'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(12) : see declaration of 'p'
C:\Program Files\Microsoft Visual Studio\MyProjects\vetor1\vetor1.cpp(31) : error C2676: binary '>' : 'class String' does not define this operator or a conversion to a type acceptable to the predefined operator
Error executing cl.exe.

vetor1.obj - 5 error(s), 0 warning(s)
运行楼上的~~~~

2006-03-31 18:26
yylcel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2005-12-10
收藏
得分:0 
那友元函数干嘛不行啊?怎么会不能访问呢error C2248: 'p' : cannot access private member declared in class 'String'
2006-03-31 21:02
yylcel
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2005-12-10
收藏
得分:0 
谢谢楼上的几位....
2006-04-01 13:06
快速回复:[求助]请教菜鸟问题!
数据加载中...
 
   



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

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