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
] 2 3364
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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>);
...
|
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...
|
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...
|
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
|
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,...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: 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...
| |