This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

C++ function pointer and pair()


Hello,

I can't access the gnats database, so i'm using email... (gnats says:
Error: Could not resolve database alias (gcc). )

I have a problem with gcc3.1. It seems that the pair() template
doesn't accepts C++ function pointers...

For example, in my CrawIRCBot class, I have:

typedef void (CrawIRCBot::*ParseServerCommandProc)(int argc, char *argv[]);
typedef map<long, ParseServerCommandProc> parserMapType;

Then if I try to insert something like that:

mParserMap.insert(parserPairType(long('TEST'), &CrawIRCBot::ParseINVITE));

I got:

CrawIRCBot.cpp:58:   instantiated from here
/usr/include/gcc/darwin/3.1/g++-v3/bits/stl_pair.h:84: could not convert `__b'
   to `void (CrawIRCBot::*&)(int, char**)'

From /usr/include/gcc/darwin/3.1/g++-v3/bits/stl_pair.h:84

  /** Two objects may be passed to a @c pair constructor to be copied.  */
  pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}

second(__b) isn't interpreted as second = __b;

gcc3.1 just doesn't want to "construct" a C++ function pointer in
that template.. (metrowerks codewarrior works well with this
code...). I don't know if the standard specifies something on it...
Currently I use a struct to encapsulate the proc ptr, as a workaround:

    typedef void (CrawIRCBot::*ParseServerCommandProc)(int argc, char *argv[]);

    struct PSCPPack { ParseServerCommandProc proc; };
    typedef map<long, PSCPPack> parserMapType;

And it works fine.

[mbuna:~/Projects/Craw/build] mbuna% gcc --version
gcc (GCC) 3.1 20020420 (prerelease)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Please drop me a mail if you have any info/suggestions about that, or
if it's already fixed in 3.2+ :-)

Regards,
--
Stéphane Thiell


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]