一个简单的问题, 还有一个比较宽泛的问题,在vc里写纯c++程序要注意些什么? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 下面的代码编译通过!#include <iostream.h>class hstring{public: hstring():p(NULL){};friend ostream &operator<<(ostream &stream,hstring &o);private: char *p; int size;};ostream &operator<<(ostream &stream,hstring &o){ stream<<o.p; return stream;}class A : public ostream{public: A():ostream(){};};int main(){ A s; hstring a; s<<a; return 0;} 看不大懂,hstring是什么啊,o.p??p是o的私有成员吧? hstring是我随便起的一个类名字,p的确是o的私有成员,但是友员函数是可以访问私有成员的. 于嘉兄,您的程序我怎么编译没出问题啊?(Borland C++ Builder) 为什么编译器会报不能访问私有变量?那么我只写一个hstring类的cpp文件的话肯定是编译不通过了是不是? 不会吧,我又编译了一遍,的确报错啊!d:\vc\test\test.cpp(16) : error C2248: 'p' : cannot access private member declared in class 'hstring' d:\vc\test\test.cpp(11): see declaration of 'p' 千真万确没有错,Turbo C++ 3.0中也编译通过. 不去省略号编译能通过么?不过VC我没试,我只用VC编辑资源,编译还有点手生. VC我试过了,huoxingang的代码,除了unsing namespace std;其他代码是原版拷贝!当然去了省略号^_^ 开玩笑吧? 去了using namespace std报了15个错啊! 按理说应该没错吧?反正Borland的C++编译器从低到高都没问题. 问题已经很明显了,就是iostream库的问题,可是这是为什么呢?其实就是我问的第二个问题,在vc下编写标准c++函数,库函数需要什么样的定义呢? MFC对话框程序中如何响应BUTTON的按下。弹起 vc ADO 用SQL语言操作数据库 有关flash与vc通信的问题,求助 一个关于字符串的问题 ado连接数据库失败 sleep函数必定导致鼠标变了,有没有延时函数又鼠标不变的啊? 我编译或全编译过工程,按运行时还是弹出对话框说:"有文件时间不对或是不存在"需要重新编译 如何添加一个IE控件的事件??????? 配料系统怎么英语说 打印高手给看看!本地打印机和网络打印机有什么区别! 一段E文,需要专业的翻译出来,很着急。i'm waiting online. 幼稚问题
class hstring
{
public:
hstring():p(NULL){};friend ostream &operator<<(ostream &stream,hstring &o);
private:
char *p;
int size;
};
ostream &operator<<(ostream &stream,hstring &o)
{
stream<<o.p;
return stream;
}class A : public ostream
{
public:
A():ostream(){};
};int main()
{
A s;
hstring a;
s<<a;
return 0;
}
d:\vc\test\test.cpp(16) : error C2248: 'p' : cannot access private member declared in class 'hstring'
d:\vc\test\test.cpp(11): see declaration of 'p'
其实就是我问的第二个问题,在vc下编写标准c++函数,库函数需要什么样的定义呢?