Re: Compile Time assertions
From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 03/31/04
- Next message: Leor Zolman: "Re: basic i/o question"
- Previous message: Mike Wahler: "Re: basic i/o question"
- In reply to: Senthilvel Samatharman: "Compile Time assertions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Mar 2004 19:19:27 +0200
Senthilvel Samatharman wrote:
> Hi,
> I was reading a topic on Compile time assertions in "Modern C++ Design"
> And i was unable to figure out how to use the technique described.
>
> I know this is a lil stupid.. but i tried and i get a error
>
> "e:\programs\test\test.cpp(10) : error C2514: 'CTAssert< ?? >' : class has
> no constructors"
>
> when i tried to compile the following program..
> #include<iostream>
>
> template <bool> class CTAssert;
>
> template <> class CTAssert<true>{};
>
> int main()
> {
> const char* const pszData = "Hello World";
> CTAssert<pszData != 0> ( );
> return 0;
> }
>
> Can someone point me where i am going wrong?
The error you get does indeed not seem to be very informative.
When compiling your test program with gcc, I get the following output:
g++ -DHAVE_CONFIG_H -I. -I. -I.. -Wcast-qual -Wshadow -Wcast-align -DNDEBUG
-DNO_DEBUG -O2 -O3 -Wall -W -Wcast-qual -Wcast-align -Wconversion
-Wmissing-prototypes -Werror -fno-exceptions -fno-check-new -fexceptions -c
main.cpp
main.cpp: In function `int main()':
main.cpp:10: error: non-constant `("Hello World" != 0)' cannot be used as
template argument
make: *** [main.o] Error 1
*** failed ***
That should make it clear what the problem is.
>
> Thanks and Best Regards,
>
> Senthilvel.
Bart v Ingen Schenau
-- a.c.l.l.c-c++ FAQ: http://ma.rtij.nl/acllc-c++.FAQ.html c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/
- Next message: Leor Zolman: "Re: basic i/o question"
- Previous message: Mike Wahler: "Re: basic i/o question"
- In reply to: Senthilvel Samatharman: "Compile Time assertions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]