function pointer trouble

This is a discussion on function pointer trouble within the C++ Programming forums, part of the General Programming Boards category; PHP Code: string :: size_type  (* find_delimiter )(const  basic_string &,  string :: size_type ); if( REVERSE_SEARCH )             find_delimiter =& ...

  1. #1
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102

    function pointer trouble

    PHP Code:
    string::size_type (*find_delimiter)(const basic_string&, string::size_type);
    if(
    REVERSE_SEARCH)
               
    find_delimiter=&string::find_last_of;
    else
               
    find_delimiter=&string::find_first_of

    Keeps giving me a parameter mismatch error.
    Either this is because find_last_of has several different versions that take didfferent types or numbers of parameters, or it's because the function pointer I declare is incorrect.

    The prototypes according to the VC++ help file is

    PHP Code:
    size_type find_last_of(E csize_type pos npos) const;
    size_type find_last_of(const *ssize_type pos npos) const;
    size_type find_last_of(const *ssize_type possize_type n npos) const;
    size_type find_last_of(const basic_stringstrsize_type pos npos) const; 
    The last one is the one I want.

    If I don't add string:: in front of size_type I get an error that size_type is undefined. So I changed it to string::size_type



    Function Pointer Tutorial that I'm using
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Correct me if I'm wrong, but it seems that you are trying to assign a pointer to a class method. Unless the method if static, I don't believe you can do this in standard C++.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

  3. #3
    Registered User WebSnozz's Avatar
    Join Date
    Oct 2001
    Posts
    102
    In the tutorial they show how to assign class member functions to function pointers and call them using the pointer, but none of the functions have complexe parameters like find_last_of does.

    One of the problems was with the multiple signatures of find_last_of. The VC++ documentation shows to add the signature in the assignment statement to define which find_last_of I want.

    I also replaced all the typedefs. The is what I have now.

    PHP Code:
    unsigned int(*find_delimiter)(const class std::basic_string &,unsigned int);
        
    find_delimiter = &string::find_last_of(const class std::basic_string &,unsigned int); 
    On the second line I get the error C2143: syntax error : missing ')' before 'const'

    Thanks in advance for the help.
    WebSnozz-
    Cats have no butt cheeks.
    If one farted, then it would make a flute noise.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 04-04-2009, 03:45 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Function Pointer help
    By Skydt in forum C Programming
    Replies: 5
    Last Post: 12-02-2005, 08:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21