0

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

1
  • ostream is in the std namespace, so you need std::ostream. Jul 11, 2012 at 16:47

3 Answers 3

5

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.

2

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.

0

you can also add using namespace std before calling ostream

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.