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{
    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);

    //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);

    //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()];
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){

//Deep Copy Destructor
delete []_data;

//Assignment Operator
IntList& IntList::operator=(const IntList &A){
    if(this != &A){
    delete[] _data;
    _data=new int [size()];
    for(int i=0;i<size();++i){
    _data[i] = A[i];
    return *this;

Many Thanks

Edited by mike_2000_17: Fixed formatting

6 Years
Discussion Span
Last Post by Banfa

>> #include <stdio.h>

Delete that line. This is c++ program, not C.

When posting code put it in code tags [code] // your code goes here [/code] so that we can read it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.