Question

Reasonably new to c++, I'm trying to use vectors in my application. I am using

#include <vector>

in the header file, but when I compile it fails on this line:

std::vector<Shot> shot_list;

Noting the error E2316 'vector' is not a member of 'std'

If I then remove std::, It results in the Undefined symbol 'vector' compiler error message. Really at a loss with this one. Had no issues using

std::list<Shot> shot_list; 

prior to using vectors.

Here is a simple example that fails to 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

To me I don't see any difference between this and This Example

Was it helpful?

Solution

Without clarifying which namespace that the vector is in, you can not use "vector" by itself. (using namespace std;) Maybe you can paste your related code for more spesific help.

Edit:

You can not initialize the vector in the .h. You need to do it in .cpp maybe using the resize() function of the vector. This can be an option for you (using the constructor of the class):

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

    private:
    std::vector<int> testVect;

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

    };

    #endif

The simple example that you have given compiles if you make the change.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top