0
votes

error LNK2001: unresolved external symbol "public: static int WrappedVector::_N" (?_N@WrappedVector@@2HA)

header.h

struct WrappedVector
{
    static int _N;
    double *_x;
};

main.cpp

const int WrappedVector::_N = 3;

i don't understand whats wrong

1

1 Answers

1
votes

Just change the definition

 int WrappedVector::_N = 3; // Note no const

see LIVE DEMO1

or the declaration

 struct WrappedVector {
    static const int _N;
        // ^^^^^
    double *_x;
 };

see LIVE DEMO2

consistently.

If you need the latter form (static const int) you can also initialize it directly in the declaration:

 struct WrappedVector {
    static const int _N = 3;
                     // ^^^
    double *_x;
 };

see LIVE DEMO3