In Haskell there is a constant called undefined
that you can use to
declare a function without defining it (i.e. a function prototype with an empty body) as with square
in
square :: Int -> Int -- declaration
square = undefined -- empty definition
main = putStrLn.show.square $ 3
This is tremendously useful to defer the work on square
and focus on getting the main
function right first, because the Haskell compiler makes sure that the whole file compiles as if square
was defined.
The C++ equivalent is
#import <iostream>
int square(int x){
//TODO incomplete
return 0;
}
int main() {
std::cout << square(3);
}
My intention is to invoke a compiler like clang++
as a typechecker for main
alone and work on square
later. Imagine that square
really is one of many not-yet-defined complex functions that return a complex data structure with a non-trivial constructor. I would have to write a lot of code to create returnable objects just to get the functions to compile.
Is there something quick-and-dirty in C++ similar to undefined
?
Thank you @molbdnilo.
Using throw
is concise and works perfectly:
int square(int x) {
throw("undefined");
}