From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7057 invoked by alias); 8 Sep 2004 20:10:34 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 7047 invoked from network); 8 Sep 2004 20:10:32 -0000 Received: from unknown (HELO mwinf0803.wanadoo.fr) (193.252.22.23) by sourceware.org with SMTP; 8 Sep 2004 20:10:32 -0000 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf0803.wanadoo.fr (SMTP Server) with SMTP id 37A6E18000D6 for ; Wed, 8 Sep 2004 22:10:32 +0200 (CEST) Received: from ANice-201-1-4-199.w81-48.abo.wanadoo.fr (ANice-201-1-4-199.w81-48.abo.wanadoo.fr [81.48.48.199]) by mwinf0803.wanadoo.fr (SMTP Server) with ESMTP id EEC2E1800046 for ; Wed, 8 Sep 2004 22:10:31 +0200 (CEST) From: Simon MARTIN To: gcc@gcc.gnu.org Subject: Type problem with template functions and inheritance ? Date: Wed, 08 Sep 2004 20:10:00 -0000 User-Agent: KMail/1.7 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200409082211.28678.simartin@users.sourceforge.net> X-SW-Source: 2004-09/txt/msg00389.txt.bz2 Hello. 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 laxist. What is strange is: - the "" 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. Regards, Simon [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 --enable-languages=c,c++,ada,f77,objc,java,pascal --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 `' to type `bool (Base::*)(const char*)' ==== test.cpp class Base {}; struct MyClass : public Base { template 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(mp); (aClass.*p1)("One"); BaseMethodPtr p2 = static_cast(&MyClass::Method<1>); (aClass.*p2)("OneAgain"); return 0; } ==== end of test.cpp -- Kile - an Integrated LaTeX Environment for KDE http://kile.sourceforge.net