Billybonks
Billybonks

Reputation: 1568

c++ library refrencing compiler error

this is a easy question but i cant seem to find the issue

    #include <iostream>
namespace utils {
    class IntList {
      public:
        IntList();                         // constructor; initialize the list to be empty
        void AddToEnd(int k);              // add k to the end of the list
        void Print(ostream &output); // print the list to output

      private:
        static const int SIZE = 10;      // initial size of the array
        int *Items;                      // Items will point to the dynamically allocated array
        int numItems;                    // number of items currently in the list
        int arraySize;                   // the current size of the array
    };
}

here i have defined a class in my header file

but it throws a compiler error saying that it cannot find a reference to ostream

Upvotes: 0

Views: 55

Answers (3)

Robin92
Robin92

Reputation: 561

you can also add using namespace std before calling ostream

Upvotes: 0

Mesop
Mesop

Reputation: 5263

The class from the stl are in the namespace std.

So, unless you are doing using namespace std, you have to prefix them with std::. In your case you should be writing std::ostream.

Upvotes: 5

ALOToverflow
ALOToverflow

Reputation: 2699

You are missing the std:: in front of ostream.

You can either :

  1. use the whole namespace before your class definition : using namespace std; ;

  2. mark that you'll be using std::ostream : using namespace std::ostream; ;

  3. or write std::ostream everywhere you need to use it.

Upvotes: 2

Related Questions