problem with std::map and VC

S

Serengeti

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::*MathFuncPtr)();
std::map<std::string, MathFuncPtr> predefinedFunctions;
// lots of other stuff
void makeDictionary(){ predefinedFunctions["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\xtree(239) : error
C2065: '_Mycont' : undeclared identifier
c:\Program Files\Microsoft Visual Studio
8\VC\include\xtree(236) : while compiling class template member function
'const std::pair<_Ty1,_Ty2>
&std::_Tree<_Traits>::const_iterator::eek:perator *(void) const'
with
[
_Ty1=const std::string,
_Ty2=Function::MathFuncPtr ,
_Traits=std::_Tmap_traits<std::string,Function::MathFuncPtr
,std::less<std::string>,std::allocator<std::pair<const
std::string,Function::MathFuncPtr >>,false>
]
c:\Program Files\Microsoft Visual Studio
8\VC\include\xtree(395) : see reference to class template instantiation
'std::_Tree<_Traits>::const_iterator' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,Function::MathFuncPtr
,std::less<std::string>,std::allocator<std::pair<const
std::string,Function::MathFuncPtr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\map(164)
: see reference to class template instantiation
'std::_Tree<_Traits>::iterator' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,Function::MathFuncPtr
,std::less<std::string>,std::allocator<std::pair<const
std::string,Function::MathFuncPtr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\map(163)
: while compiling class template member function 'void (Function::*
&std::map<_Kty,_Ty>::eek:perator [](const
std::basic_string<_Elem,_Traits,_Ax> &))(void)'
with
[
_Kty=std::string,
_Ty=Function::MathFuncPtr,
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
d:\Documents and Settings\Serengeti\Moje dokumenty\My
Projects\Derivatives\Derivatives\function.h(36) : see reference to class
template instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=std::string,
_Ty=Function::MathFuncPtr
]
 
V

Victor Bazarov

Serengeti said:
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::*MathFuncPtr)();
std::map<std::string, MathFuncPtr> predefinedFunctions;
// lots of other stuff
void makeDictionary(){ predefinedFunctions["sin"]=&F::f_sin(); }

Replace

&F::f_sin()

with

&Function::f_sin

.. 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\xtree(239) : error
C2065: '_Mycont' : undeclared identifier
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(236)
: while compiling class template member function 'const
std::pair<_Ty1,_Ty2> &std::_Tree<_Traits>::const_iterator::eek:perator
*(void) const'
with
[
_Ty1=const std::string,
_Ty2=Function::MathFuncPtr ,
_Traits=std::_Tmap_traits<std::string,Function::MathFuncPtr
,std::less<std::string>,std::allocator<std::pair<const
std::string,Function::MathFuncPtr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(395)
: see reference to class template instantiation
'std::_Tree<_Traits>::const_iterator' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,Function::MathFuncPtr
,std::less<std::string>,std::allocator<std::pair<const
std::string,Function::MathFuncPtr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\map(164) :
see reference to class template instantiation
'std::_Tree<_Traits>::iterator' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,Function::MathFuncPtr
,std::less<std::string>,std::allocator<std::pair<const
std::string,Function::MathFuncPtr >>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\map(163) :
while compiling class template member function 'void (Function::*
&std::map<_Kty,_Ty>::eek:perator [](const
std::basic_string<_Elem,_Traits,_Ax> &))(void)'
with
[
_Kty=std::string,
_Ty=Function::MathFuncPtr,
_Elem=char,
_Traits=std::char_traits<char>,
_Ax=std::allocator<char>
]
d:\Documents and Settings\Serengeti\Moje dokumenty\My
Projects\Derivatives\Derivatives\function.h(36) : see reference to class
template instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=std::string,
_Ty=Function::MathFuncPtr
]
 
S

Serengeti

Victor said:
Replace

&F::f_sin()

with

&Function::f_sin

. 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::*MathFuncPtr)();
std::map<std::string, MathFuncPtr> predefinedFunctions;
// lots of other stuff
void makeDictionary(){ predefinedFunctions["sin"]=&Function::f_sin; }
};

So I guess the problem is somewhere else.

thanks for answering,
Slawek
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top