473,722 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

problem with std::map and VC

Hello,
in my class I have a map that translates strings to pointers to some
member functions. The code goes like this:

class F {
typedef void (Function::*Mat hFuncPtr)();
std::map<std::s tring, MathFuncPtr> predefinedFunct ions;
// lots of other stuff
void makeDictionary( ){ predefinedFunct ions["sin"]=&F::f_sin(); }
};

Code like this works all right in gcc, but causes a strange compile
time error[*] in VC (from MSVC++ 2005 express beta).
I'd be happy to know if it's my or VC's fault :)

TIA,
Slawek


[*]:

c:\Program Files\Microsoft Visual Studio 8\VC\include\xt ree(239) : error
C2065: '_Mycont' : undeclared identifier
c:\Program Files\Microsoft Visual Studio
8\VC\include\xt ree(236) : while compiling class template member function
'const std::pair<_Ty1, _Ty2>
&std::_Tree<_Tr aits>::const_it erator::operato r *(void) const'
with
[
_Ty1=const std::string,
_Ty2=Function:: MathFuncPtr ,
_Traits=std::_T map_traits<std: :string,Functio n::MathFuncPtr
,std::less<std: :string>,std::a llocator<std::p air<const
std::string,Fun ction::MathFunc Ptr >>,false>
]
c:\Program Files\Microsoft Visual Studio
8\VC\include\xt ree(395) : see reference to class template instantiation
'std::_Tree<_Tr aits>::const_it erator' being compiled
with
[
_Traits=std::_T map_traits<std: :string,Functio n::MathFuncPtr
,std::less<std: :string>,std::a llocator<std::p air<const
std::string,Fun ction::MathFunc Ptr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\ma p(164)
: see reference to class template instantiation
'std::_Tree<_Tr aits>::iterator ' being compiled
with
[
_Traits=std::_T map_traits<std: :string,Functio n::MathFuncPtr
,std::less<std: :string>,std::a llocator<std::p air<const
std::string,Fun ction::MathFunc Ptr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\ma p(163)
: while compiling class template member function 'void (Function::*
&std::map<_Kty, _Ty>::operator [](const
std::basic_stri ng<_Elem,_Trait s,_Ax> &))(void)'
with
[
_Kty=std::strin g,
_Ty=Function::M athFuncPtr,
_Elem=char,
_Traits=std::ch ar_traits<char> ,
_Ax=std::alloca tor<char>
]
d:\Documents and Settings\Sereng eti\Moje dokumenty\My
Projects\Deriva tives\Derivativ es\function.h(3 6) : see reference to class
template instantiation 'std::map<_Kty, _Ty>' being compiled
with
[
_Kty=std::strin g,
_Ty=Function::M athFuncPtr
]
Jul 22 '05 #1
2 3400
Serengeti wrote:
Hello,
in my class I have a map that translates strings to pointers to some
member functions. The code goes like this:

class F {
typedef void (Function::*Mat hFuncPtr)();
std::map<std::s tring, MathFuncPtr> predefinedFunct ions;
// lots of other stuff
void makeDictionary( ){ predefinedFunct ions["sin"]=&F::f_sin(); }
Replace

&F::f_sin()

with

&Function::f_si n

.. notice that (a) there are no parentheses and (b) the class name is not
'F', but 'Function'.
};

Code like this works all right in gcc, but causes a strange compile
time error[*] in VC (from MSVC++ 2005 express beta).
I'd be happy to know if it's my or VC's fault :)

TIA,
Slawek

[*]:

c:\Program Files\Microsoft Visual Studio 8\VC\include\xt ree(239) : error
C2065: '_Mycont' : undeclared identifier
c:\Program Files\Microsoft Visual Studio 8\VC\include\xt ree(236)
: while compiling class template member function 'const
std::pair<_Ty1, _Ty2> &std::_Tree<_Tr aits>::const_it erator::operato r
*(void) const'
with
[
_Ty1=const std::string,
_Ty2=Function:: MathFuncPtr ,
_Traits=std::_T map_traits<std: :string,Functio n::MathFuncPtr
,std::less<std: :string>,std::a llocator<std::p air<const
std::string,Fun ction::MathFunc Ptr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\xt ree(395)
: see reference to class template instantiation
'std::_Tree<_Tr aits>::const_it erator' being compiled
with
[
_Traits=std::_T map_traits<std: :string,Functio n::MathFuncPtr
,std::less<std: :string>,std::a llocator<std::p air<const
std::string,Fun ction::MathFunc Ptr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\ma p(164) :
see reference to class template instantiation
'std::_Tree<_Tr aits>::iterator ' being compiled
with
[
_Traits=std::_T map_traits<std: :string,Functio n::MathFuncPtr
,std::less<std: :string>,std::a llocator<std::p air<const
std::string,Fun ction::MathFunc Ptr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\ma p(163) :
while compiling class template member function 'void (Function::*
&std::map<_Kty, _Ty>::operator [](const
std::basic_stri ng<_Elem,_Trait s,_Ax> &))(void)'
with
[
_Kty=std::strin g,
_Ty=Function::M athFuncPtr,
_Elem=char,
_Traits=std::ch ar_traits<char> ,
_Ax=std::alloca tor<char>
]
d:\Documents and Settings\Sereng eti\Moje dokumenty\My
Projects\Deriva tives\Derivativ es\function.h(3 6) : see reference to class
template instantiation 'std::map<_Kty, _Ty>' being compiled
with
[
_Kty=std::strin g,
_Ty=Function::M athFuncPtr
]

--
Please remove capital As from my address when replying by mail
Jul 22 '05 #2
Victor Bazarov wrote:
Replace

&F::f_sin()

with

&Function::f_si n

. notice that (a) there are no parentheses and (b) the class name is not
'F', but 'Function'.


well I've basically messed things up when preparing a code example for
the posting :) My real code looks exactly like your suggestion:

class Function {
typedef void (Function::*Mat hFuncPtr)();
std::map<std::s tring, MathFuncPtr> predefinedFunct ions;
// lots of other stuff
void makeDictionary( ){ predefinedFunct ions["sin"]=&Function::f_s in; }
};

So I guess the problem is somewhere else.

thanks for answering,
Slawek
Jul 22 '05 #3

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

Similar topics

3
30065
by: Woodster | last post by:
I have declared the following std::map<std::string, std::string> myMap; to pass myMap to functions should I be declaring functions as: void function(std::map<std::string, std::string>); or is there a preferred/better method of doing this?
19
6159
by: Erik Wikström | last post by:
First of all, forgive me if this is the wrong place to ask this question, if it's a stupid question (it's my second week with C++), or if this is answered some place else (I've searched but not found anything). Here's the problem, I have two sets of files, the name of a file contains a number which is unique for each set but it's possible (even probable) that two files in different sets have the same numbers. I want to store these...
1
6478
by: Avery Fong | last post by:
The following program will result in a compile error when building under Debug but will compile under Release. Why does is work under Release mode but not under Debug This program is developed under Visual Studio .NET 2003 in a Win32 Console Project // VectorInsert.cpp : Defines the entry point for the console application / #include "stdafx.h #include "VectorInsert.h #ifdef _DEBU
13
9673
by: kamaraj80 | last post by:
Hi I am using the std:: map as following. typedef struct _SeatRowCols { long nSeatRow; unsigned char ucSeatLetter; }SeatRowCols; typedef struct _NetData
4
6248
by: Evyn | last post by:
Hi all, I'm starting to fool around with STL and in particular std::map. How do I iterate through one map and insert every pair in another map? I have the following so far: map<double, doublefset1; map<double, doublefset3;
7
6262
by: DevNull | last post by:
Hi there everyone, I'm creating a very simple immediate mode command interpreter. The final purpose is to provide a pluggable control and command console for a MUD server I have written. The basic theory is we wrap the functions we want exposed to the console in a function with a prototype of int func(State*)
2
5376
by: digz | last post by:
Hi, I am trying to write a program which has two threads one of them write to a map , and the other one deletes entries based on a certain criterion.. first I cannot get the delete portion to work , what am i missing here. also is it possible/correct that the removeKeyValue function acquire the mutex lock only during the call to map.erase(), and not the during the whole iteration process as i have done here( i logically felt it was...
7
5837
by: Matthias Pfeifer | last post by:
Hi there, a std::map is build from std::pair elements where for a pair p p.first is called the key and p.second the value. Is there a way to keep the map sorted by the values? Ie is there a std::key_compare in the stl that offeres this functionality? It's ok if this would make finding a key more expensive. Writing my own would be possible, but why do it if it's already there... matthias
8
4071
by: mveygman | last post by:
Hi, I am writing code that is using std::map and having a bit of an issue with its performance. It appears that the std::map is significantly slower searching for an element then a sequential search in a vector. Has anyone run into this before?
0
8863
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6681
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4502
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
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 we have to send another system
2
2602
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.