[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hpux-cxx-dev
Subject:    Re: CXX-DEV: Snipet from Modern C++ Design book
From:       Martin Sebor <sebor () roguewave ! com>
Date:       2002-12-19 17:12:39
[Download RAW message or body]

Mark Crosland wrote:
> Hello, trying to compile a code snipet from Modern C++ Design book.
> 
> HP 11.11 aCC: HP ANSI C++ B3910B A.03.33
> 
> typhoon:/homedir/markc > aCC convert.cpp 
> Error 284: "convert.cpp", line 23 # Called function must return completed
>     object type or void.
>             enum { exists = sizeof(Test(MakeT())) == sizeof(Small) };
>                                         ^^^^^^^                      
> For what it is worth, it compiles with gcc and Sun CC.
> 
> If I modify the first instance of sizeof() below to sizeof(Test(char*)) I
> get an error indicating that you can't take sizeof() a function.

We worked around it by changing exists from an enum to a static
const bool data member (see below).

Regards
Martin


template <class T, class U> class Convertible;

template <class T>
class Convertible<T,T> {

     public:
         enum { exists = 1, sameType = 1 };
};

template <class T, class U>
class Convertible {

     private:
         typedef char Small;
         class Big { char dummy[2]; };
         static Small Test(U);
         static Big Test(...);
         static T MakeT();

     public:
         static const bool exists = sizeof(Test(MakeT())) == sizeof(Small);
         enum { sameType = false };

};

template <class T, class U>
const bool Convertible<T, U>::exists;
 _________________________________________________________________
 To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
    with the message UNSUBSCRIBE cxx-dev
 _________________________________________________________________
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic