From: Chris on 29 Nov 2006 10:36 Chris wrote: > I am reading a file and when I read a certain string I want to execute a > certain function. > > This is the code i have but I must be doing something wrong, it doesn't > compile. I am using c++ (GCC) 3.4.6 20060404 on a RHEL 4 workstation > There are three functions in class Convert "void Convert::writeVerts()", > "void Convert::writeCell(int)" and "void Convert::writeBoun ()" > > typedef void (Convert::*FUNCPTR )( void ) ; > typedef void (Convert::*FUNCPTR2)( int ) ; > typedef std::map< std::string,FUNCPTR >::value_type MapItem; > typedef std::map< std::string,FUNCPTR2 >::value_type MapItem2; > std::map< std::string, FUNCPTR > FunctionTable; > > FunctionTable.insert(MapItem(std::string("$* GRID CARDS"),writeVerts)); > FunctionTable.insert(MapItem2(std::string("$* ELEMENT > CARDS"),writeCell)); FunctionTable.insert(MapItem(std::string("$* LOAD > AND CONSTRAINT CARDS" ) , > writeBoun ) ); > > The compile error I get is > > error: no matching function for call to `std::pair<const std::string, void > (Convert::*)()>::pair(std::string, <unresolved overloaded function type>)' > > candidates are: std::pair<const std::string, void (Convert::* > ()>::pair(const std::pair<const std::string, void (Convert::*)()>&) Thank you for every one that replied on my post, and gave me advice. At the end this is how I did it. typedef void (Convert::*FUNCPTR )( void ) ; typedef std::map< std::string,FUNCPTR > MapItem; MapItem functionTable; functionTable["$* GRID CARDS"] = &Convert::writeVerts; functionTable["$* ELEMENT CARDS"] = &Convert::writeCell; functionTable["$* LOAD AND CONSTRAINT CARDS"] = &Convert::writeBoun;
First
|
Prev
|
Pages: 1 2 Prev: istream& problem Next: Visual Studio 2005 Professional, errors C2039 C2873 |