TheExp1.h
template < class elemType >
class Array
{
public:
explicit Array( int size = DefaultArraySize );
Array( elemType *array, int Array_size );
Array( const Array &rhs );
virtual ~Array(){ delete [] ia; }
bool operator==( const Array& )const;
bool operator!=( const Array& )const;
Array& operator=( const Array& );
int size() const { return _size; }
virtual elemType operator[]( int index ){ return ia[index]; }
virtual void sort();
virtual elemType min() const;
virtual elemType max() const;
virtual int find( const elemType &value ) const;
protected:
int _size;
elemType *ia;
static const int DefaultArraySize = 12;
};
TheExp1.cpp
#include "iostream"
#include "TheExp1.h"
using namespace std;
int main()
{
const int array_size = 4;
Array<int> ia(array_size);
Array<char> ca(array_size);
Array<double> da(array_size);
int ix;
for ( ix = 0; ix < array_size; ++ix)
{
ia[ ix ] = ix;
da[ ix ] = ix * 1.75;
ca[ ix ] = ix + 'a';
}
for ( ix = 0; ix < array_size; ++ix)
cout << "[" << ix << "] ia:" << ia[ ix ]
<< "\tca:" << ca[ ix ]
<< "\tda:" << da[ ix ] << endl;
return 0;
}
錯誤為
ia[ ix ] = ix;
da[ ix ] = ix * 1.75;
ca[ ix ] = ix + 'a';
編譯器提示錯誤原因:
error C2106: “=”: 左操作数必须为左值
請高手幫忙作答
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!