This is the mail archive of the gcc-help@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]
Other format: [Raw text]

Re: Using local struct with templates


dinonet@gmx.de writes:

> Hi, I've got a problem with using a template together with a struct
> declared inside a function body, see example below. When I compile
> "g++ -D TEST1 test.cpp" or "g++ -D TEST2 test.cpp" the compiler
> answers with "error: no matching function for call to
> Buffer:read()'". "g++ -D TEST3 test.cpp" compiles and runs as expected
> but is using a globally defined struct.
>
> Can someone tell me if this compiler error is a bug in the compiler or
> something not covered by the C++ standard? Is there any other
> workaround besides making the struct global?

The compiler is correct.  The C++98 standard forbids instantiating a
template with a local type.  This restriction is lifted in the draft
C++0x standard, and indeed current versions of gcc do compile your
code with the -std=c++0x option.

Ian


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