473,410 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,410 software developers and data experts.

Reference Errors with vectors

here is my code:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

class command {
public:
static void tokenizer(string str, vector<string>& words, string
delimiter){
string::size_type pos1 = 0;
string::size_type pos2 = str.find_first_of(delimiter);
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
while(pos2 <= str.length()){
pos2 = str.find_first_of(delimiter, pos1);
if(pos2 > str.length()){
pos2 = str.length();
}
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
pos2 += 1;
}
}
static void getCommand(){
string c;
cin >> c;
tokenizer(c, com, " ");
if(com.size() == 1){
cout << com[1] << "\n";
} else if(com.size() == 2){
cout << com[1] << "\n" << com[2] << "\n";
} else { cout << "invalid command!\n"; }
}
private:
static vector<string> com;
};

int main()
{
command::getCommand();
return 0;
}

Here is the error I get when I compile:

/tmp/ccNSmcoY.o: In function `command::getCommand()':
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x70): undefined
reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0xeb): undefined
reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x104):
undefined reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x135):
undefined reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x14e):
undefined reference to `command::com'
/tmp/ccNSmcoY.o:command.cpp:(.gnu.linkonce.t._ZN7comman d10getCommandEv+0x165):
more undefined references to `command::com' follow
collect2: ld returned 1 exit status


If anyone can find something please let me know. thanks in advance.

May 26 '06 #1
4 1496
Felix85 wrote:
here is my code:

#include <iostream>
#include <string>
#include <vector>

using namespace std;

class command {
public:
static void tokenizer(string str, vector<string>& words, string
delimiter){
string::size_type pos1 = 0;
string::size_type pos2 = str.find_first_of(delimiter);
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
while(pos2 <= str.length()){
pos2 = str.find_first_of(delimiter, pos1);
if(pos2 > str.length()){
pos2 = str.length();
}
words.push_back(str.substr(pos1 ,pos2 - pos1));
pos1 = pos2 + 1;
pos2 += 1;
}
}
static void getCommand(){
string c;
cin >> c;
tokenizer(c, com, " ");
if(com.size() == 1){
cout << com[1] << "\n";
} else if(com.size() == 2){
cout << com[1] << "\n" << com[2] << "\n";
} else { cout << "invalid command!\n"; }
}
private:
static vector<string> com;
Static data members have to be _defined_ at the namespace level.
Isn't this already in the FAQ?
};
Put here:

vector<string> command::com;

int main()
{
command::getCommand();
return 0;
}

Here is the error I get when I compile:

/tmp/ccNSmcoY.o: In function `command::getCommand()':
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x70):
undefined reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0xeb):
undefined reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x104):
undefined reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x135):
undefined reference to `command::com'
command.cpp:(.gnu.linkonce.t._ZN7command10getComma ndEv+0x14e):
undefined reference to `command::com'
/tmp/ccNSmcoY.o:command.cpp:(.gnu.linkonce.t._ZN7comman d10getCommandEv+0x165):
more undefined references to `command::com' follow
collect2: ld returned 1 exit status


If anyone can find something please let me know. thanks in advance.


Please read the FAQ before posting.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 26 '06 #2
that doesn't work, ive already tried that. It just gives me the same
error.

May 26 '06 #3
Felix85 wrote:
that doesn't work, ive already tried that. It just gives me the same
error.


What are you talking about? What doesn't work?
May 26 '06 #4
I still get the same error after trying what you said to do. Unless im
not understanding what you are trying to have me do.

May 26 '06 #5

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

Similar topics

27
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
3
by: Amit | last post by:
Hello. I am having some problem organizing a set of vectors. The vectors itself, could contain a pointer( say integer pointer) or could contain another object MyClass. 1>So, first of all, is...
8
by: Bo Peng | last post by:
Dear list, I am using std::vector<bool> (bit_vector) to store my bit sequence. To access the same sequence from C (to expose to a python module), I need to know the pointer and offset of...
4
by: aaronfude | last post by:
Hi, Please consider the following class (it's not really my class, but it's a good example for my question): class Vector { int myN; double *myX; Vector(int n) : myN(n), myX(new double) { }...
16
by: Niels L Ellegaard | last post by:
Is there a module that allows me to find errors that occur due to copy by reference? I am looking for something like the following: Traceback (most recent call last): File "<stdin>", line 1, in...
1
nabh4u
by: nabh4u | last post by:
Hi, I have a problem referencing to Vectors using pointers i.e. I am not able to use "call by reference" on vector variables. I have a "read()" function in "x.cpp" and "main()" in "y.cpp". I...
3
Digital Don
by: Digital Don | last post by:
I have a problem sending the Vectors as Referencial parameters..i.e. I am having a struct vector struct board { int r; int c; };
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
3
by: Victor Bazarov | last post by:
jl_post@hotmail.com wrote: Yes, certainly. Actually 'delete' is an operator, not a function. The parens are superfluous. There is really no need for that.
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.