Dear all,
I had some replies on my previous post.But wanted to learn sth. Static
member functions of a class can access only the static data members of
the same class. So this principle in mind, lets advance one step
further,
lets say in a class I have a map in the private declerations of the
class
private:
static map<string, vector<string> > m_;
and in the public part
public:
static void Initialize_();
And in the implementation file of the class, inside the Initialize_()
function I am trying to initialize the static map like
m_["g"].push_back("x");
m_["g"].push_back("x");
m_["g"].push_back("z");
This looks logically true to me but compilation does not agree with
that. It results in an undefined reference error.
And for nearly one day, I have not been able to figure out the problem.
Regards, 5 2316
utab wrote: Static member functions of a class can access only the static data members of the same class. So this principle in mind, lets advance one step further,
lets say in a class I have a map in the private declerations of the class
private: static map<string, vector<string> > m_;
and in the public part
public:
static void Initialize_();
And in the implementation file of the class, inside the Initialize_() function I am trying to initialize the static map like
m_["g"].push_back("x"); m_["g"].push_back("x"); m_["g"].push_back("z");
std::map does not have a push_back member function, so the above code
is a syntax error. What is it you are trying to do? You could try:
m_["g"] = "x";
But I'm not sure that's what you're trying to do.
This looks logically true to me but compilation does not agree with that. It results in an undefined reference error.
In the future, you would make our lives much easier if you followed FAQ
5.8: http://www.parashift.com/c++-faq-lit...t.html#faq-5.8
In particular, post compilable code and post the complete text of the
error message you get.
In addition to the above error, make sure you consult FAQ section
10.11: http://www.parashift.com/c++-faq-lit...html#faq-10.11
Best regards,
Tom
"utab" <um********@gmail.com> wrote in message
news:11*********************@i39g2000cwa.googlegro ups.com... Dear all,
I had some replies on my previous post.But wanted to learn sth. Static member functions of a class can access only the static data members of the same class. So this principle in mind, lets advance one step further,
lets say in a class I have a map in the private declerations of the class
private: static map<string, vector<string> > m_;
and in the public part
public:
static void Initialize_();
And in the implementation file of the class, inside the Initialize_() function I am trying to initialize the static map like
m_["g"].push_back("x"); m_["g"].push_back("x"); m_["g"].push_back("z");
This looks logically true to me but compilation does not agree with that. It results in an undefined reference error.
That's correct because, although you have declared 'm_', you have not
defined it (class-static data members must be defined). In your
implementation file, add something like:
map<string, vector<string> > <classname>::m_;
....where <classname> is the name of your class (which you didn't give
above).
- Dennis
"Thomas Tutone" <Th***********@yahoo.com> wrote in message
news:11**********************@j33g2000cwa.googlegr oups.com... utab wrote:
std::map does not have a push_back member function, so the above code is a syntax error. What is it you are trying to do? You could try:
No, but a vector does, and the data type of the second template parameter in
his map declaration is a vector. Thus, given:
map<string, vector<string> > m_;
....then
m_[ "somestring" ]
....refers to a vector
- Dennis
Thomas Tutone wrote: utab wrote:
Static member functions of a class can access only the static data members of the same class. So this principle in mind, lets advance one step further,
lets say in a class I have a map in the private declerations of the class
private: static map<string, vector<string> > m_;
and in the public part
public:
static void Initialize_();
And in the implementation file of the class, inside the Initialize_() function I am trying to initialize the static map like
m_["g"].push_back("x"); m_["g"].push_back("x"); m_["g"].push_back("z"); std::map does not have a push_back member function, so the above code is a syntax error.
Oops - I was asleep at the wheel - I somehow missed that it was a
std::map< std::string, std::vector< std::string> >. Sorry about that.
In addition to the above error, make sure you consult FAQ section 10.11:
http://www.parashift.com/c++-faq-lit...html#faq-10.11
That advice still stands.
Best regards,
Tom
Dennis Jones wrote: "Thomas Tutone" <Th***********@yahoo.com> wrote in message news:11**********************@j33g2000cwa.googlegr oups.com... utab wrote:
std::map does not have a push_back member function, so the above code is a syntax error. What is it you are trying to do? You could try:
No, but a vector does, and the data type of the second template parameter in his map declaration is a vector. Thus, given:
map<string, vector<string> > m_;
...then
m_[ "somestring" ]
...refers to a vector
Absolutely right - see my other post. And thanks for the correction.
Best regards,
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Marcin Vorbrodt |
last post by:
So I have a class Math that looks like this:
Math {
public:
static Real PI(void);
};
Real Math::PI(void) {
return 4.0 * atan(1.0);
}
|
by: Alfonso Morra |
last post by:
Hi,
I have a function declared thus:
int foo( int, int );
In the definition, I want to have a variable that is expensive to
create. I want to be able to save the state of this variable...
|
by: Dennis |
last post by:
I have a function which is called from a loop many times. In that function,
I use three variables as counters and for other purposes. I can either use
DIM for declaring the variables or Static. ...
|
by: Ronald Bruck |
last post by:
I have several routines which are used millions of times in my
programs, using the Gnu multi-precision software's floating-point reals
(see <http://www.swox.se/gmp>). These are of type mpf_t, and...
|
by: Per Bull Holmen |
last post by:
Hey
Im new to c++, so bear with me. I'm used to other OO languages, where it
is possible to have class-level initialization functions, that
initialize the CLASS rather than an instance of it....
| |
by: Zytan |
last post by:
I see that static is more restricted in C# than in C++. It appears
usable only on classes and methods, and data members, but cannot be
created within a method itself. Surely this is possible in...
|
by: Sandro Bosio |
last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long.
I'm trying to achieve the...
|
by: Pramod |
last post by:
Hello to all of you,
I want to know that what's the use to create static object.
Thanks You
Pramod Sahgal
|
by: tomPee |
last post by:
Hi,
I have the following problem:
I am trying to make some sort of base class menu that i can then use to derive other menu's from. Those menu's should then be able to interact with each other....
|
by: Timothy Madden |
last post by:
Hy
static members of non-integral type need to be declared in the class,
but defined (and constructed or initialized) outside the class.
Like this
class SystemName
{
public:
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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: 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...
|
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...
|
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: 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...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |