2012-07-11 29 views
0

這是一個簡單的問題,但我似乎無法找到問題C++庫refrencing編譯器錯誤

#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 
    }; 
} 

在這裏,我已經在我的頭文件

定義一個類,但它拋出一個編譯器錯誤,說它找不到對ostream的引用

+0

'ostream'是在'std'命名空間前添加using namespace std,所以你需要'的std :: ostream'。 – 2012-07-11 16:47:54

+0

非常感謝非常感謝:D! – Billybonks 2012-07-11 16:50:57

+0

如果它解決了你的問題。請將問題標記爲已回答。謝謝。 – ALOToverflow 2012-07-11 16:52:15

回答

5

stl中的類位於命名空間std中。

所以,除非你在做using namespace std,你必須以std::爲前綴。在你的情況下,你應該寫std::ostream

2

您在ostream前面缺少std::

您可以:

  1. 使用整個命名空間的類定義之前:using namespace std;;

  2. 標記您將使用std :: ostream:using namespace std::ostream;;

  3. 或寫無論你需要使用它。