473,503 Members | 11,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unresolved external symbol linker error with a vector which is a static member variable

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);
}
Jul 22 '05 #1
4 4871
On Sat, 18 Dec 2004 16:01:54 +0100 in comp.lang.c++, "Serge"
<se***@NOSPAM.com> wrote,
//define static member variables
vector<int> m_variable_v;


Should be:
vector<int> myclass::m_variable_v;

Jul 22 '05 #2
Great ! Thanks very much for your quick solution.
Best regards,
Serge

"David Harmon" <so****@netcom.com> wrote in message
news:42****************@news.west.earthlink.net...
On Sat, 18 Dec 2004 16:01:54 +0100 in comp.lang.c++, "Serge"
<se***@NOSPAM.com> wrote,
//define static member variables
vector<int> m_variable_v;


Should be:
vector<int> myclass::m_variable_v;

Jul 22 '05 #3

"Serge" <se***@NOSPAM.com> wrote in message
news:41***********************@news.skynet.be...
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
This is a declaration, not a definition. No actual object has
been created. And still no vector object will be created
if you create a type 'myclass' object, because 'static' means
that the member is not stored as part of a 'myclass' object,
but separately, only once. I.e. 'm_variable_v's scope is
your class, but it is not actually part of a 'myclass' object.

You need to provide (exactly one)
definition of your static vector.
};

//myclass.cpp
//cource code class

#include "myclass.h"

using namespace std;

//define static member variables
vector<int> m_variable_v;
Not quite right. This defines a vector which is *not*
in your class' scope. It has nothing to do with your
class or any objects of that type.

vector<int> myclass::m_variable_v;
void myclass::my_method(int new_value)
See how you've qualified 'my_method' as being a member
of 'myclass' here? Same is required for static data members.
{
m_variable_v.push_back(new_value);
}

-Mike
Jul 22 '05 #4
"Serge" <se***@NOSPAM.com> wrote in
news:41***********************@news.skynet.be:
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 [...] //define static member variables
vector<int> m_variable_v;


vector<int> myclass::m_variable_v;

HTH
Paavo
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2756
by: Ida | last post by:
Hi, I am trying to build an dll with Microsoft Visual C++ but during the linking phase I get linking errors. Script.obj : error LNK2019: unresolved external symbol __imp__PyString_AsString...
6
26331
by: Olivier Lechenne | last post by:
I am converting some projects from VS 6.0 to VS .NET 2003 and I get a linker error error LNK2001: unresolved external symbol ___security_cookie or error LNK2001: unresolved external symbol...
2
3620
by: Sai Kit Tong | last post by:
I try to utilize an old native code class library for my managed C++ application, and experience a weird problem. I used IJW approach and included the header file for my native class definition. I...
5
17707
by: cschettle | last post by:
I think you need to link with msvcrt.lib ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000...
2
1765
by: Ian Taite | last post by:
Help, I am trying to nail a linking problem, to avoid having to lose about 2 weeks work. I have a backup of my project that compiles and links OK however changes I made sometime since then have...
2
5300
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
7129
by: Maydogg6 | last post by:
I need a hand with some stubborn link errors. I'm trying to recreate and old program from 6.0 into .NET, but for some reason when I try to compile I'm getting linking errors for all my function...
3
3146
by: curious2007 | last post by:
I am getting the following type of error: 1>Compiling manifest to resources... 1>Linking... 1>main.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall...
0
2694
by: Ryan Gaffuri | last post by:
hlink72@hotmail.com (Eric) wrote in message news:<ab8d8b14.0308220550.54fb5f22@posting.google.com>... LNK1120 is a standard C++ error. you using Visual C++? Means your references a class that...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5604
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.