Error LNK1120: 4 unresolved externals --Initializing class vector variable inside constructor

I am trying to link a vector of vectors from my header file to my .cpp file, but I am getting a couple errors in the form of:

Error 5 error LNK1120: 4 unresolved externals

Error 1 error LNK2020: unresolved token (0A00001A) "private: static class std::vector >,class std::allocator > > > * Radix::negArrayPtr" (?negArrayPtr@Radix@@$$Q0PAV?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@A)

Error 2 error LNK2020: unresolved token (0A00001C) "private: static class std::vector >,class std::allocator > > > * Radix::zeroArrayPtr" (?zeroArrayPtr@Radix@@$$Q0PAV?$vector@V?$vector@HV?$allocator@H@std@@@std@@V?$allocator@V?$vector@HV?$allocator@H@std@@@std@@@2@@std@@A)

and 2 other errors similar to the previous 2 (Error 1 and 2).

Here is my code:

Radix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "stdafx.h"
#include "Radix.h"

using namespace std;


Radix::Radix(int cols)
{

   zeroArrayPtr = new vector< vector <int> >;
   negArrayPtr  = new vector< vector <int> >;

   if (zeroArrayPtr->size() == 0)
   {
   createArrays(cols);
   }
}

void Radix::createArrays(int cols)


Radix.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef RADIX_H
#define RADIX_H

#include <iostream>
#include <math.h>
#include <vector>
#include <stack>

using namespace std;

class Radix
{
  public:
       Radix(int cols);

  private:
       void createArrays(int cols);

       static vector<vector<int> > *zeroArrayPtr;
       static vector<vector<int> > *negArrayPtr;
};

#endif // RADIX_H 


It obviously has something to do with the static vector of vectors (zeroArrayPtr and negArrayPtr), however, I cannot figure out what. Thanks in advance for your help!
static members need to be instantiated.

Put this in the cpp file, like after your 'using namespace std' line:

1
2
vector<vector<int> >* Radix::zeroArrayPtr;
vector<vector<int> >* Radix::negArrayPtr;


EDIT: wrong term.
Last edited on
[joke]
¿what's worst than a multidimensional array?
A pointer to a multidimensional array

Oh my, those leaks. Better wrap it in an smart pointer
std::unique_ptr< std::vector<std::vector<int> > > zeroArrayPtr;
Much better
[/joke]

Seriously, ¿why don't you use objects?
Topic archived. No new replies allowed.