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. 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
that doesn't work, ive already tried that. It just gives me the same
error.
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?
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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.
|
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...
|
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...
|
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) { }...
|
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...
|
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...
|
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;
};
|
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...
|
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.
|
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
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |