 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Serge Guest
|
Posted: Sun Dec 19, 2004 1:52 am Post subject: unresolved external symbol linker error with a vector which |
|
|
Hi,
I have no problem creating a static member variable with integers, etc but
when I try the same with a vector then I always get linker errors that the
static member variable is unknown (unresolved external symbol)
Below is what an example of the code I use. Can somebody tell me what I am
doing wrong ?
Thanks very much in advance,
Serge
//myclass.h
//header file
#include <vector>
using namespace std;
class myclass
{
public:
static void my_method (int new_value);
private:
static vector<int> m_variable_v; //static member variable
};
//myclass.cpp
//cource code class
#include "myclass.h"
using namespace std;
//define static member variables
vector<int> m_variable_v;
void myclass::my_method(int new_value)
{
m_variable_v.push_back(new_value);
}
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Ivan Vecerina Guest
|
Posted: Sun Dec 19, 2004 9:51 am Post subject: Re: unresolved external symbol linker error with a vector wh |
|
|
"Serge" <serge (AT) NOSPAM (DOT) com> wrote
| Quote: | I have no problem creating a static member variable with integers, etc but
when I try the same with a vector then I always get linker errors that the
static member variable is unknown (unresolved external symbol)
Below is what an example of the code I use. Can somebody tell me what I am
doing wrong ?
....
class myclass
{
public:
static void my_method (int new_value);
private:
static vector<int> m_variable_v; //static member variable
};
....
//define static member variables
vector<int> m_variable_v;
|
Should be:
vector<int> myclass::m_variable_v;
Written as above, you were defining a new variable in namespace scope.
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Branimir Maksimovic Guest
|
Posted: Sun Dec 19, 2004 9:55 am Post subject: Re: unresolved external symbol linker error with a vector wh |
|
|
Serge wrote:
| Quote: | Hi,
I have no problem creating a static member variable with integers,
etc but
when I try the same with a vector then I always get linker errors
that the
static member variable is unknown (unresolved external symbol)
Below is what an example of the code I use. Can somebody tell me what
I am
doing wrong ?
class myclass
{
public:
static void my_method (int new_value);
private:
static vector<int> m_variable_v; //static member variable
};
//myclass.cpp
//cource code class
#include "myclass.h"
using namespace std;
//define static member variables
vector<int> m_variable_v;
|
Classic error. You didn't define class member vector rather
global vector.
Use this syntax:
vector<int> myclass::m_variable_v;
Greetings, Bane.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Torsten Robitzki Guest
|
Posted: Mon Dec 20, 2004 12:42 am Post subject: Re: unresolved external symbol linker error with a vector wh |
|
|
Serge wrote:
| Quote: | Hi,
I have no problem creating a static member variable with integers, etc but
when I try the same with a vector then I always get linker errors that the
static member variable is unknown (unresolved external symbol)
Below is what an example of the code I use. Can somebody tell me what I am
doing wrong ?
Thanks very much in advance,
Serge
//myclass.h
//header file
#include <vector
using namespace std;
class myclass
{
public:
static void my_method (int new_value);
private:
static vector
};
//myclass.cpp
//cource code class
#include "myclass.h"
using namespace std;
//define static member variables
vector<int> m_variable_v;
|
this is just an other variable with the name m_variable_v. The name of
the static class variable is myclass::m_variable_v.
regards Torsten
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
M Jared Finder Guest
|
Posted: Mon Dec 20, 2004 12:42 am Post subject: Re: unresolved external symbol linker error with a vector wh |
|
|
Serge wrote:
| Quote: | Hi,
I have no problem creating a static member variable with integers, etc but
when I try the same with a vector then I always get linker errors that the
static member variable is unknown (unresolved external symbol)
Below is what an example of the code I use. Can somebody tell me what I am
doing wrong ?
Thanks very much in advance,
Serge
//myclass.h
//header file
#include <vector
using namespace std;
class myclass
{
public:
static void my_method (int new_value);
private:
static vector
};
//myclass.cpp
//cource code class
#include "myclass.h"
using namespace std;
//define static member variables
vector<int> m_variable_v;
|
vector<int> myclass::m_variable_v; // specify the class or this is
// just a normal global
| Quote: |
void myclass::my_method(int new_value)
{
m_variable_v.push_back(new_value);
}
|
-- MJF
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|