我正处于家庭作业的中间,我们的任务是编写操作符重载函数,并给出一个名为xArray.h的头文件,如下所示:
#ifndef XARRAY_H_
#define XARRAY_H_
#include <stddef.h>
#include <memory.h>
#include <iostream>
using namespace std;
class xArray{
size_t len;
size_t arraySize;
//data of int array
int* data;
public:
// Constructors
xArray();
xArray(const xArray& a);
xArray(const int x);//create an array with x elements
//copy constructor to get n integer from an C style array,
//n is assumed to be < the length of of that array
xArray(const int * a, size_t n);
// Destructor
~xArray();
// Assignment and modification operators
xArray& operator=(const xArray& right);
//make the array hold only one integer
xArray& operator=(const int c);
//merge two arrays, append all elements from right to the end of this
xArray& operator+=(const xArray& right);
//add c to the end of this array
xArray& operator+=(const int c);
// Put an int at the end of data, can be used by operators "+=", ">>"
size_t PushBack(const int c);
// Put an int at the beginning of the data.
size_t PushFront(const int c);
// set len to 0, i.e. the array is cleared
void Clear(void);
// index operator, if idx over bound, print message and quit
int operator[](size_t idx) const;
//get the length of the xArray&
size_t Length() const { return len; }
//overloaded << operator, print all elements of the array. A line can at most
//hold 20 elements
friend ostream& operator<<(ostream& out, const xArray& a);
//>> operator, get one int and put it at the end of the array
friend istream& operator>>(istream& in, xArray& a);
};
#endif
我试图在朋友istream&amp;内部调用PushBack()函数。运算符&gt;&gt;(istream&amp; in,xArray&amp; a)我在.cpp文件中编写的函数,如下所示:
istream& operator>>(istream& in, xArray& a)
{
a.*PushBack(in);
}
但我收到错误说:
error: ‘PushBack’ was not declared in this scope
到目前为止,我已经尝试了Google能够提供给我的所有内容,但没有任何效果。