public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Vaclav Haisman <V.Haisman@sh.cvut.cz>
To: Simon MARTIN <simartin@users.sourceforge.net>
Cc: gcc@gcc.gnu.org
Subject: Re: Type problem with template functions and inheritance ?
Date: Wed, 08 Sep 2004 21:33:00 -0000	[thread overview]
Message-ID: <20040908233105.B16173@logout.sh.cvut.cz> (raw)
In-Reply-To: <200409082211.28678.simartin@users.sourceforge.net>


Because Comeau's test drive compiler accepts I would fill a bug report in
Bugzilla if I were you.

VH


On Wed, 8 Sep 2004, Simon MARTIN wrote:

> 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 "<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.
>
> 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 `<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);
>   (aClass.*p1)("One");
>
>   BaseMethodPtr p2 = static_cast<BaseMethodPtr>(&MyClass::Method<1>);
>   (aClass.*p2)("OneAgain");
>
>   return 0;
> }
> ==== end of test.cpp
>
> --
> Kile - an Integrated LaTeX Environment for KDE
> http://kile.sourceforge.net
>

  reply	other threads:[~2004-09-08 21:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-08 20:10 Simon MARTIN
2004-09-08 21:33 ` Vaclav Haisman [this message]
2004-09-08 22:41 Type problem with template functions and inheritance? Wolfgang Bangerth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040908233105.B16173@logout.sh.cvut.cz \
    --to=v.haisman@sh.cvut.cz \
    --cc=gcc@gcc.gnu.org \
    --cc=simartin@users.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).