• Advertisement

Archived

This topic is now archived and is closed to further replies.

C++: Generating compile-time warnings or errors

This topic is 5744 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am in the process of writing a class overloading the new and delete operators. For this particular class, however, it makes no sense, and is definitely an error, to use the operators new[] and delete[]. So I would want to overload those operators, but have them generate a compile-time warning or error. I have absolutely no idea how to do this, or if it is even possible. Is there some standard way of signalling to the compiler that it should generate a warning or error? If there is no standard way of doing it, is there a way to do it that is Visual C++ specific? Help or URL''s highly appreciated. -Neophyte -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+ PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+ ----- END GEEK CODE BLOCK----- geekcode.com

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
You may want to check out the preprocessor commands #error and #warning.

You can also use asserts for this type of thing to generate a run-time error instead of a compile-time one.

Share this post


Link to post
Share on other sites
Overload them and make them private . Since they''ll never be called you only need the declaration.

Share this post


Link to post
Share on other sites
Thanks SabreMan and spock, I can''t believe I didn''t think of that myself. (*bonks head on keyboard repeatedly*).

Anyway, AP: The Preprocessor commands are definitely not going to work, as they will generate error/warning regardless of wether the operators are ever used or not. And asserts will only work in debug-mode, and not in release-mode.

-Neophyte

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GED d- s:+ a- C++$ UL++ P++ L++ E W+ N+ o K? w !O M--(+) V-- PS+
PE Y+ PGP t-- 5++ X+ R(+) rv+(++) b+++ DI+ D(+) G e+>++ h r--> y+
----- END GEEK CODE BLOCK-----
geekcode.com

Share this post


Link to post
Share on other sites

  • Advertisement