This is the mail archive of the 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]

Type problem with template functions and inheritance ?


I played a little with templates and template functions, and I encountered a 
problem with GCC while doing so. The code at the end of this message builds 
with Microsoft's Visual C++ Toolkit 2003, but fails with GCC. Since the code 
is quite "weird", I wonder whether there's a problem in GCC or Visual is too 

What is strange is:
  - the "<unknown type>" in the error message
  - the fact that if I "help" GCC a little (before the first static_cast), 
then things work fine.

Thanks in advance for your help / explanation.


[simon@texel gcc_test]$ g++ -v
Reading specs from /usr/lib/gcc-lib/i586-mandrake-linux-gnu/3.3.2/specs
Configured with: ../configure --prefix=/usr --libdir=/usr/lib 
--with-slibdir=/lib --mandir=/usr/share/man --infodir=/usr/share/info 
--enable-shared --enable-threads=posix --disable-checking --enable-long-long 
--enable-__cxa_atexit --enable-clocale=gnu 
--host=i586-mandrake-linux-gnu --with-system-zlib
Thread model: posix
gcc version 3.3.2 (Mandrake Linux 10.0 3.3.2-6mdk)

[simon@texel gcc_test]$ g++ -Wall -o test test.cpp
test.cpp: In function `int main(int, char**)':
test.cpp:18: error: invalid static_cast from type `<unknown type>' to type 
`bool (Base::*)(const char*)'

==== test.cpp
class Base {};
struct MyClass : public Base
  template<int key> bool Method(const char *value) { return true; }

int main(int argc, char *argv[])
  typedef bool (Base::*BaseMethodPtr)(const char*);
  typedef bool (MyClass::*MethodPtr)(const char*);

  MyClass aClass;

  MethodPtr mp = &MyClass::Method<1>;
  BaseMethodPtr p1 = static_cast<BaseMethodPtr>(mp);

  BaseMethodPtr p2 = static_cast<BaseMethodPtr>(&MyClass::Method<1>);

  return 0;
==== end of test.cpp

Kile - an Integrated LaTeX Environment for KDE

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