Skip to main content
GameDev.net gamedev.net
🔒 Locked

C++: Generating compile-time warnings or errors

Started by Neophyte May 30, 2002 at 10:43 AM 3 replies 1.1k views
Original Post
Neophyte
Neophyte
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
SabreMan
SabreMan
Make ''em private - you only need to declare them.
spock
spock
Overload them and make them private . Since they''ll never be called you only need the declaration.
Neophyte
Neophyte
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.