* Re: I can not compile code from <<modern c++ design>>
[not found] ` <5.1.0.14.2.20030408164530.0320de40@m2.qualcomm.com>
@ 2003-04-08 11:30 ` Matthias Oltmanns
2003-04-09 7:06 ` Di Yang
0 siblings, 1 reply; 2+ messages in thread
From: Matthias Oltmanns @ 2003-04-08 11:30 UTC (permalink / raw)
To: Di Yang; +Cc: gcc-help, gcc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: I can not compile code from <<modern c++ design>>
2003-04-08 11:30 ` I can not compile code from <<modern c++ design>> Matthias Oltmanns
@ 2003-04-09 7:06 ` Di Yang
0 siblings, 0 replies; 2+ messages in thread
From: Di Yang @ 2003-04-09 7:06 UTC (permalink / raw)
To: Matthias Oltmanns; +Cc: gcc-help, gcc
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-04-09 0:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <5.1.0.14.2.20030407215046.03878f90@m2.qualcomm.com>
[not found] ` <5.1.0.14.2.20030407172155.03ff8788@m2.qualcomm.com>
[not found] ` <5.1.0.14.2.20030408164530.0320de40@m2.qualcomm.com>
2003-04-08 11:30 ` I can not compile code from <<modern c++ design>> Matthias Oltmanns
2003-04-09 7:06 ` Di Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).