-2
데이터 []의 내용을 출력하는 행을 제거하면 잘 컴파일됩니다. 구현 파일을 통해 배열에 액세스하는 데 문제가있는 것 같습니다. 어떤 도움이 필요합니다.<< 연산자를 오버로드 할 때 구현 파일에서 헤더 파일의 배열에 액세스하려면 어떻게해야합니까?
구현 파일 기능 :
ostream& operator << (ostream& output, const Bag& b1)
{
for(int i = 0; i< b1.used; i++)
{
output <<Bag.data[i]<<" "; // LINE OF ERROR
}
output<<endl;
return output;
}
헤더 파일 :
#ifndef BAG_H
#define BAG_H
#include <cstdlib>
#include <fstream>
namespace greg_bag{
using namespace std;
class Bag
{
public:
typedef int value_type;
typedef std:: size_t size_type;
static const size_type CAPACITY = 30;
Bag(){used = 0;}
void erase();
bool erase_one(const value_type& target);
void insert (const value_type& entry);
//void operator += (const bag& addend);
//size_type size()const {return used;}
//size_type count(const value_type& target) const;
//bag operator +(const bag& b1, const bag& b2);
friend ostream& operator << (ostream&, const Bag&);
private:
value_type data[CAPACITY];
size_type used;
};
}
#endif
오류 메시지 : 오류 : '.'전에 예상되는 주요 표현 토큰 |
'출력 << b1.data [i] << "" –