undefined reference to Array::operator[](int)
Can someone help me fix the error on line 61 thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
#include <iostream>
const int defaultsize = 10;
class Array
{
public:
// constructors
Array(int itsSize = defaultsize);
Array(const Array & rhs);
~Array() { delete [] pType;}
// operators
Array& operator=(const Array &);
int& operator[] (int offset);
const int& operator[] (int offset) const;
// accessors
int GetitsSize() const { return itsSize;}
//friend function
friend std::ostream& operator<< (std::ostream&, const Array&);
// define the exception classes
class xBoundary {};
class xTooBig {};
class xTooSmall {};
class xTerm {};
class xNegative {};
class xZero {};
private:
int *pType;
int itsSize;
};
Array::Array(int size):
itsSize(size)
{
if(size == 0)
throw xZero();
if(size<10)
throw xTooSmall();
if (size > 3000)
throw xTooBig();
if(size < 1)
throw xNegative();
pType = new int[size];
for(int i = 0; i<size; i++)
pType[i] = 0;
}
int main()
{
try
{
Array intArray(0);
for (int j = 0; j< 100; j++)
{
intArray[j] = j;
std::cout<<"intArray[" <<j<< "j okay..."<<std::endl;
}
}
catch(Array::xBoundary)
{
std::cout <<"Unable to process the input!\n";
}
catch (Array::xTooBig)
{
std::cout<<"This array is too big..."<<std::endl;
}
catch (Array::xTooSmall)
{
std::cout<<"This array is too small..."<<std::endl;
}
catch(Array::xZero)
{
std::cout<<"The programmer asked for an array of zero objects"<<std::endl;
}
catch (...)
{
std::cout<<"Something went wrong, bit i've no idea what!"<<std::endl;
}
std::cout <<"Done\n";
}
|
Last edited on
Topic archived. No new replies allowed.