[問題] operator <<的問題

看板C_and_CPP作者 (叮噹)時間15年前 (2009/05/06 17:07), 編輯推噓1(106)
留言7則, 3人參與, 最新討論串1/1
我的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

05/06 17:27, , 1F
這跟<<毫無關係吧. 類別的介面沒有容許你Access的話.
05/06 17:27, 1F

05/06 17:27, , 2F
把private改成public不就解決了.?
05/06 17:27, 2F

05/06 17:42, , 3F
可是作業需求要PRIVATE..
05/06 17:42, 3F

05/06 18:02, , 4F
看到vc6又是朋友~ 那這樣請您下載更新檔吧~
05/06 18:02, 4F

05/06 18:02, , 5F
因為那是VC6的bug(要是你沒更新至sp6的話)
05/06 18:02, 5F

05/06 18:03, , 6F
懶得更新也ok~ 那就把實作寫到class內吧~ :p
05/06 18:03, 6F

05/06 19:30, , 7F
謝謝W大 我的朋友終於理我了
05/06 19:30, 7F
文章代碼(AID): #1A0LDEeE (C_and_CPP)