作者h12258 (叮噹)
看板C_and_CPP
標題[問題] operator <<的問題
時間Wed May 6 17:07:25 2009
我的CLASS
BigInt.h
#include <malloc.h>
#include <iostream>
#include <string.h>
using namespace std;
#ifndef BIGINT_H
#define BIGINT_H
class BigInt {
friend ostream& operator<<(ostream &output , BigInt &x);
private:
char * _digits; // Array: 儲存字元
int _capacity; // Array 大小
int _numDigits; // 整數位數
int _sign; // 正負號 正1 負-1
}
#endif
BigInt.cpp
#include "bigint.h"
ostream& operator<<(ostream& output,BigInt& x){
for( int i=x._capacity-1; i>=0; i-- )
if(x._digits[i]!=0)
break;
if(x._sign==-1&&i!=-1)
output<<"-";
if( x._numDigits == 0 ||i==-1)
output << '0';
else
for(; i>=0; i-- ){
if((int)x._digits[i]<10 &&i != x._capacity-2)
output<<0;
output << (int)x._digits[i];}
output << endl;
return output;
}
雖然身為朋友 可是BigInt卻不肯把private的變數借出來
這樣算什麼朋友(我是VC6)
error C2248: '_capacity' : cannot access private member declared in class
'BigInt'
該怎麼修改呢ˊˋ
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.174.4
1F:推 NDark:這跟<<毫無關係吧. 類別的介面沒有容許你Access的話. 05/06 17:27
2F:→ NDark:把private改成public不就解決了.? 05/06 17:27
3F:→ h12258:可是作業需求要PRIVATE.. 05/06 17:42
4F:→ windincloud:看到vc6又是朋友~ 那這樣請您下載更新檔吧~ 05/06 18:02
5F:→ windincloud:因為那是VC6的bug(要是你沒更新至sp6的話) 05/06 18:02
6F:→ windincloud:懶得更新也ok~ 那就把實作寫到class內吧~ :p 05/06 18:03
7F:→ h12258:謝謝W大 我的朋友終於理我了 05/06 19:30