From: FE on
I want to implement a Lightweight static_assert:
template<bool>
struct StaticCheckError;
template<>
struct StaticCheckError<true>
{
typedef int type;
};

#ifndef STATIC_ASSERT
#define STATIC_ASSERT(V) typedef StaticCheckError< bool(V) >::type
StaticCheck
#endif

in general ,is work:
void assert_test()
{
STATIC_ASSERT(5-4);
}
int template, is no work:
template<int NUM>
void assert_test()
{
STATIC_ASSERT(NUM-4);
}
error: too few template-parameter-lists|

How can it be? CodeBlocks 10.05+mingw gcc 4.4.1

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: Johannes Schaub (litb) on
FE wrote:

> I want to implement a Lightweight static_assert:
> template<bool>
> struct StaticCheckError;
> template<>
> struct StaticCheckError<true>
> {
> typedef int type;
> };
>
> #ifndef STATIC_ASSERT
> #define STATIC_ASSERT(V) typedef StaticCheckError< bool(V) >::type
> StaticCheck
> #endif
>
> in general ,is work:
> void assert_test()
> {
> STATIC_ASSERT(5-4);
> }
> int template, is no work:
> template<int NUM>
> void assert_test()
> {
> STATIC_ASSERT(NUM-4);
> }
> error: too few template-parameter-lists|
>
> How can it be? CodeBlocks 10.05+mingw gcc 4.4.1
>

Put "typename" before StaticCheckError< ... >::type. The compiler otherwise
can't know whether this is a type-name

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

From: FE on
On 8��2��, ����1ʱ54��, "Johannes Schaub (litb)" <schaub-johan...(a)web.de>
wrote:
>
> Put "typename" before StaticCheckError< ... >::type. The compiler otherwise
> can't know whether this is a type-name
>

typename only can use in template. now
void assert_test()
{
STATIC_ASSERT(5-4);


}
can't compile


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

 | 
Pages: 1
Prev: type casting issue
Next: Why error?