2012-04-20 158 views
3

對於C++來說,合理的新手,我試圖在我的應用程序中使用向量。 我使用Borland C++ Builder 6 - E2316'vector'不是'std'的成員

#include <vector> 
在頭文件

,但是當我編譯它在這條線失敗:

std::vector<Shot> shot_list; 

注意到錯誤E2316「載體」不是「STD」

的成員

如果我然後刪除std ::,它導致未定義的符號'向量'編譯器錯誤消息。真的在這一個損失。在使用載體之前沒有使用的問題

std::list<Shot> shot_list; 

下面是一個簡單的例子,不能comile:

//--------------------------------------------------------------------------- 

#ifndef testclassH 
#define testclassH 
//--------------------------------------------------------------------------- 
#include <vector> 
class TestClass { 
     private: 
     std::vector<int> testVect(1); // removing std:: and adding using namespace std; below the include for the vector it still fails to compile; 

}; 

#endif 

要我,我不看到這一點,This Example

+0

您對'testVect'的聲明是錯誤的。擺脫'(1)'部分,它應該只是'std :: vector testVect;'本身。 – 2012-05-02 22:21:00

回答

3

之間有什麼區別沒有澄清其命名空間矢量是,你可以本身不使用「矢量」。 (使用命名空間標準;)也許你可以粘貼你的相關代碼獲得更多的特定幫助。

編輯:

您不能在.h中初始化向量。你需要在.cpp中使用vector的resize()函數來完成。這可能是一個選擇(使用類的構造函數):

#ifndef testclassH 
    #define testclassH 
    //--------------------------------------------------------------------------- 
    #include <vector> 
    class TestClass { 

    private: 
    std::vector<int> testVect; 

    public: 
    TestClass() 
    { 
     testVect.resize(4); 
    } 

    }; 

    #endif 

你給編譯,如果你做出改變的簡單例子。