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: I can not compile code from <<modern c++ design>>


At 13:02 4/7/2003 +0200, Matthias Oltmanns wrote:
Am Mon, 2003-04-07 um 11.24 schrieb Di Yang:
> Hi,
>
> public:
> enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };

Hi,

this seems to be not valid C++ code because the calls to the
static members 'Test' and 'MakeT' are not const expressions at compile
time.
For assignments to enum literals there are only integer expressions
allowed which are evaluated at compile time.

cu
Matthias

Thank you, I changed the code as following and passed GCC 3.2: -Di


        template <class T, class U>
        struct ConversionHelper
        {
            typedef char Small;
            struct Big { char dummy[2]; };
            static Big   Test(...);
            static Small Test(U);
            static T MakeT();
        };

template <class T, class U>
struct Conversion
{
typedef ConversionHelper<T, U> H;
enum { exists = sizeof(typename H::Small) == sizeof(H::Test(H::MakeT())) };


    };
......


C:\ttt>g++ -o template template.cpp template.cpp: In instantiation of `Conversion<double, int>': template.cpp:40: instantiated from here template.cpp:40: warning: passing `double' for argument 1 of `static char ConversionHelper<T, U>::Test(U) [with T = double, U = int]'

C:\ttt>template
1 0
C:\ttt>

--
Matthias Oltmanns

Tel: 04421-1543-274
mail: Mathias dot Oltmanns dot Oltmanns at sysde dot eads dot net


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