friend function cann't access private data?

kof99th 2002-05-04 09:00:41
#ifndef BIGNUM_H
#define BIGNUM_H
#include <iostream>
using namespace std;
class bignum
{
public:
bignum(int i=40);
bignum(const bignum&);
~bignum();
bignum& operator = (const bignum& b);
void getinput(istream&);
private:
int* element;
int size;
int currentsize;

public:
//friend const bignum operator + (const bignum& b1,const bignum& b2);如果加上这句,有一个错误:fatal error 1001.why?
friend ostream& operator<<(ostream&,const bignum&);
friend istream& operator>>(istream&,bignum&);
friend const bignum operator*(const bignum& b1,const bignum& b2);

};
#endif
//bugnum.cpp
........
ostream& operator <<(ostream& out,const bignum& b)
{
for(int i=b.currentsize;i>0;i--)
out<<b.element[i-1];
return out;
}
.......
complier error:cann't access private data currentsize and element declare
in class bignum;
why?I use vc6.0,if i use bc,code is well.
...全文
138 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shornmao 2002-05-06
  • 打赏
  • 举报
回复
这是VC6对namespace支持的问题,碰到这种情况,已知的解决办法就是你已经发现的不用namespace,改用老式的<***.h>
kof99th 2002-05-06
  • 打赏
  • 举报
回复
如果我把using namespace std;去掉,把include <iostream> 改为include
<iostream.h>就可以了,why?
messagebox 2002-05-05
  • 打赏
  • 举报
回复
friend function can access the private data
the code is correct
AMin2001 2002-05-04
  • 打赏
  • 举报
回复
你用什么编译器啊
fsht 2002-05-04
  • 打赏
  • 举报
回复
vc中也没有事
fsht 2002-05-04
  • 打赏
  • 举报
回复
我在dev-C++中调试
#ifndef BIGNUM_H
#define BIGNUM_H
#include <iostream>
using namespace std;
class bignum
{
public:
bignum(int i=40);
bignum(const bignum&);
~bignum();
bignum& operator = (const bignum& b);
void getinput(istream&);
private:
int* element;
int size;
int currentsize;

public:
friend const bignum operator + (const bignum& b1,const bignum& b2);
friend ostream& operator<<(ostream&,const bignum&);
friend istream& operator>>(istream&,bignum&);
friend const bignum operator*(const bignum& b1,const bignum& b2);

};
#endif

没事阿

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧