2012-04-20 159 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 

你给编译,如果你做出改变的简单例子。