C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

unresolved external symbol linker error with a vector which

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Serge
Guest





PostPosted: Sun Dec 19, 2004 1:52 am    Post subject: unresolved external symbol linker error with a vector which Reply with 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<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





PostPosted: Sun Dec 19, 2004 9:51 am    Post subject: Re: unresolved external symbol linker error with a vector wh Reply with quote



"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





PostPosted: Sun Dec 19, 2004 9:55 am    Post subject: Re: unresolved external symbol linker error with a vector wh Reply with quote




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





PostPosted: Mon Dec 20, 2004 12:42 am    Post subject: Re: unresolved external symbol linker error with a vector wh Reply with quote

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





PostPosted: Mon Dec 20, 2004 12:42 am    Post subject: Re: unresolved external symbol linker error with a vector wh Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.