alex wrote:[color=blue]
> I read famous book "Modern C++ Design". In chapter 2, there is a
> STATIC_CHECK sample:
> --------------------------------------------------
> template < bool >
> struct CompileTimeChecker
> {
> CompileTimeChecker(...);
> };
>
> template <>
> struct CompileTimeChecker< false >
> {};
>
> #define STATIC_CHECK( expr, msg )\
> {\
> class ERROR_##msg{};\
> ( void )sizeof( CompileTimeChecker< ( expr ) >( ERROR_##msg() )
> );\
> }
>
> ---------------------------------------------------------
> I use STATIC_CHECK, but get a error:
> ISO C++ forbids applying `sizeof' to a function type
>
> Why this error? Why use sizeof?
>
> thanks![/color]
Seems you are using one of the early prints of the book (or they never
moved the online errata in the new prints)
On the website of Alexandrescu (
http://www.moderncppdesign.com/) there
is more errata for the book.
The fix is IIRC
( void )sizeof( CompileTimeChecker< ( expr ) >(( ERROR_##msg()
))
Difference is the extra pair of () around ERROR_##msg()