I can not compile code from <<modern c++ design>>
Di Yang
diy@qualcomm.com
Wed Apr 9 07:06:00 GMT 2003
At 12:00 4/8/2003 +0200, Matthias Oltmanns wrote:
>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.
I don't know either, can someone familiar c++ standard explain this?
And with a FooHelper, it works:
// code start
#include <iostream>
template <typename T>
class FooHelper
{
public:
static T bar();
};
template<typename T>
class Foo
{
public:
enum { test = sizeof(FooHelper<T>::bar()) };
};
int main()
{
std::cout << Foo<char>::test << std::endl;
}
// code end
Thanks.
Di
>cu
>Matthias
More information about the Gcc
mailing list