I can not compile code from <<modern c++ design>>
Matthias Oltmanns
Mathias.Oltmanns.Oltmanns@sysde.eads.net
Tue Apr 8 09:57:00 GMT 2003
Am Die, 2003-04-08 um 10.48 schrieb Di Yang:
>
> Sorry, but I still failed at this point:
>
Hmmm ... me too :-) I've tested yesterday the wrong file.
I've learned, that using sizeof with a function as parameter is a
constant integer expression and therefore valid in using
enumeration initializers.
The question remaining is, why does the following not compile:
#include <iostream>
template<typename T>
class Foo
{
public:
static T bar();
enum { test = sizeof(bar()) };
};
int main()
{
std::cout << Foo<char>::test << std::endl;
}
> g++ -o conv conv.cc
conv.cc: In instantiation of `Foo<char>':
conv.cc:14: instantiated from here
conv.cc:14: invalid use of undefined type `class Foo<char>'
conv.cc:5: declaration of `class Foo<char>'
conv.cc:14: enumerator value for `test' not integer constant
> g++ --version
g++ (GCC) 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
Is it a bug or does i still miss some point.
cu
Matthias
More information about the Gcc-help
mailing list