I would like to create a compile-time error in my C++ code with a custom error message. I want to do this for a couple of reasons:
I'm sure there is a trick to doing this but I cant find a resource explaining the method. I would wrap the code in a #define of the form COMPILE_FAIL("error message");
Thanks D
Use #error
:
#error "YOUR MESSAGE"
This produces an error from the preprocessor. If you want to detect an error at a later stage (e.g. during template processing), use static_assert
(a C++11 feature).