Re: Using local struct with templates

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



dinonet@xxxxxx 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux