468,771 Members | 1,778 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

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::*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
2 3085
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
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.

Similar topics

3 posts views Thread by Woodster | last post: by
19 posts views Thread by Erik Wikström | last post: by
13 posts views Thread by kamaraj80 | last post: by
4 posts views Thread by Evyn | last post: by
7 posts views Thread by DevNull | last post: by
2 posts views Thread by digz | last post: by
7 posts views Thread by Matthias Pfeifer | last post: by
8 posts views Thread by mveygman | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.