Hey, im new to C++, and im trying to create a class IntList.
I am getting errors at compile time with one line, but i have no clue why!
Could someone please help, so i know what needs changing or why the errors are occuring.
The errors occuring are:-
error C2872: 'ostream' : ambiguous symbol
error C2065: 'sout' : undeclared identifier
error C2059: syntax error : 'const'
Sorry if the answer is really simple.
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <assert.h>
using namespace std;
class IntList{
public:
//constructors
IntList(int size=10, int value=0);
IntList(const int A[], int n);
//gang of three
IntList(const IntList &A);
IntList & operator=(const IntList &A);
~IntList();
//inspector for the size of the list
int size() const;
//inspector for the element of constant list
const int& operator[](int i) const;
//inspector/mutator for the element
//of nonconstant list
int& operator[] (int i);
//resize list
void resize(int n=0, int val=0);
private:
//data members
int* _data; //pointer to elements
int _size; //size of list
}
//IntList auxiliary functions -- nonmembers
ostream& operator<<(ostream &sout, const IntList &A);[COLOR="red"]Error Occurring here[/COLOR]
istream& operator>>(istream &sin, IntList &A);
//Deafault Constrctor
IntList::IntList(int numOfElements, int defaultValue){
assert(numOfElements >0);
_size = numOfElements;
_data = new int [size()];
assert(_data);
for(int i =0; i<size(); ++i){
_data[i] = defaultValue;
}
}
//Deep Copy Constructor
IntList::IntList(const IntList &A){
_size = A.size();
_data = new int [size()];
for(int i =0; i<size(); ++i){
_data[i]=A[i];
}
}
//Deep Copy Destructor
IntList::~IntList(){
delete []_data;
}
//Assignment Operator
IntList& IntList::operator=(const IntList &A){
if(this != &A){
delete[] _data;
_size=A.size();
_data=new int [size()];
for(int i=0;i<size();++i){
_data[i] = A[i];
}
}
return *this;
}
Many Thanks