By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,478 Members | 1,833 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,478 IT Pros & Developers. It's quick & easy.

problem with std::map and VC

P: n/a
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::operator *(void) const'
with
[
_Ty1=const std::string,
_Ty2=Function::MathFuncPtr ,
_Traits=std::_Tmap_traits<std::string,Function::Ma thFuncPtr
,std::less<std::string>,std::allocator<std::pair<c onst
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::Ma thFuncPtr
,std::less<std::string>,std::allocator<std::pair<c onst
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::Ma thFuncPtr
,std::less<std::string>,std::allocator<std::pair<c onst
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>::operator [](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
]
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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::*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::operator
*(void) const'
with
[
_Ty1=const std::string,
_Ty2=Function::MathFuncPtr ,
_Traits=std::_Tmap_traits<std::string,Function::Ma thFuncPtr
,std::less<std::string>,std::allocator<std::pair<c onst
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::Ma thFuncPtr
,std::less<std::string>,std::allocator<std::pair<c onst
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::Ma thFuncPtr
,std::less<std::string>,std::allocator<std::pair<c onst
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>::operator [](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
]

--
Please remove capital As from my address when replying by mail
Jul 22 '05 #2

P: n/a
Victor Bazarov wrote:
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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.