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]

pointers to overloaded member functions



I think there is a problem in name resolution of pointers to overloaded 
member functions. Here is a simple test case:

// file: Char.h
// a character class
class Char {

public:
  char internal_data;

  // constructors and destructors
  ...

  // a method which is not overloaded
  // 
  inline int not_overload(Char& in_char) {

    // call the overloaded method
    return gt(in_char);
  }

  // overloaded methods
  // 
  inline int gt(Char& in_char) {
    // call the lower method
    return gt(in_char.internal_data);
  }
  inline int gt(char in_char) {
    return (internal_data > in_char);
  }
}

// file: test.cc
// a test class
#include "Char.h"

class Test {
public:

  // data
  Char internal_char;

  // a simple comparison method
  //
  inline int compare(boolean (Char::*method_a)(Char&)) {

    internal_char_d = 'a';
    Char compare_char('b');

    // see which is greater
    int grthan = (internal_char_d.*method_a)(compare_char);

    if (!grthan) {
      fprintf(stdout, "a less than b\n");
    }
    else {
      fprintf(stdout, "a greater than b\n");
    }
    return grthan;
  }
};

int main(int argc, char** argv) {

  // create a test class
  Test test_class;

  // test case 1 - this creates a compiler error
  test_class.compare(&Char::gt);

  // test case 2 - this works
  test_class.compare(&Char::not_overload);
}


...
If I comment out test case 1 then it works fine. If I comment out test case 2
then I get the following



isip22_[1]: gcc -v
Reading specs from /usr/local/gnu/lib/gcc-lib/i386-pc-solaris2.6/2.95.1/specs
gcc version 2.95.1 19990816 (release)

isip22_[1]: make
gcc -I. -Wall  -g -c  test.cc
test.cc: In function `int main(int, char **)':
test.cc:41: no matching function for call to `Test::compare ({unknown type})'
test.cc:15: candidates are: boolean Test::compare(int (Char::*)(Char &))
make: *** [test.o] Error 1

isip22_[1]: uname -a
SunOS isip22.isip.msstate.edu 5.6 Generic_105182-06 i86pc i386 i86pc


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