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]

implicit conversion from "pointer to function" to "void*"


Hi,

in C++ it's possible to implicitly convert a pointer to a function to void*.

But g++ complains when it comes to overload resolution.

If I feed the following program to g++ (egcs-2.91.60) I get the error report

test.c: In function `void test()':
test.c:21: no matching function for call to `Test::Test (int ()(int))'
test.c:5: candidates are: Test::Test(const Test &)
test.c:4:                 Test::Test(void *)

SUN CC does not complain.

Bye

Klaus

-------------------------------------------------------------------------------------------

test program:

struct Test
{
  void *p;
  Test(void* q) {p=q;}
};

typedef int (*FPTR)(int a);

int Function(int a)
{
   return 1;
}

void test()
{
  FPTR  f = Function;
  // a pointer to a function can be assigned to void*
  // i.e. it can be implicitly converted to void*
  void* p = Function;
  // so this should also be possible
  Test  t(Function);
}

--
----------------------------------------------------------------------
Klaus Bergdolt                    EMail: Klaus.Bergdolt@de.bosch.com
Bosch Telecom GmbH
Abteilung UC-ON/EUE1
Gerberstr. 33                     Phone: (+49 | 0) 7191 13 3198
D-71522 Backnang                  Fax:   (+49 | 0) 7191 13 4320
----------------------------------------------------------------------




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