Problem with forward declaration of classes with nested templates

Steven Keuchel steven.keuchel@gmail.com
Mon Sep 25 21:56:00 GMT 2006


Hey,

the following piece of code doesn't compile, although I can't think of
anything why it shouldn't. Reversing the order of the declaration of
struct a and b solves this, which is kinda irritating. Any idea why
this isn't compiling? and maybe a quote from teh standard about this?

Thanks in advance,
 Steven

-----------------
struct b;

struct a : public b::impl<0>
{};

struct b
{
    template<int>
    struct impl
    {};
};
-----------------

g++ -v -c forward_test.cpp
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --enable-checking=release
i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20060920 (prerelease) (Ubuntu 4.1.1-13ubuntu3)
 /usr/lib/gcc/i486-linux-gnu/4.1.2/cc1plus -quiet -v -D_GNU_SOURCE
forward_test.cpp -quiet -dumpbase forward_test.cpp -mtune=generic
-auxbase forward_test -version -fstack-protector -fstack-protector -o
/tmp/cc5JIJA9.s
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2
 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/i486-linux-gnu
 /usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.1.2/include
 /usr/include
End of search list.
GNU C++ version 4.1.2 20060920 (prerelease) (Ubuntu 4.1.1-13ubuntu3)
(i486-linux-gnu)
        compiled by GNU C version 4.1.2 20060920 (prerelease) (Ubuntu
4.1.1-13ubuntu3).
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129480
Compiler executable checksum: c3f2c9ee44f31617ad714092aa741e6d
forward_test.cpp:3: error: expected template-name before '<' token
forward_test.cpp:3: error: expected `{' before '<' token
forward_test.cpp:3: error: expected unqualified-id before '<' token



More information about the Gcc-help mailing list