Lets say i have a Shape object that has a constructor like this:
Shape( width, height, radius, depth )
Now, I just have a silly rect so i dont need redius and depth… is it okey to do
Shape myRect(50, 50, NULL, NULL) ?
I know its not the best idea and I should use inheritance and stuff but this is the mess im in so can i use NULL like this?
Depends on what types radius and depth are. If they are integers, you have to use an out-of-bound value like -1 to indicate “not set” (out-of-bound could also be 0 if you declare it that way). If they are pointers, NULL could be used.
Actually what you describe is a common example of bad inheritance, and it’s used in OOP teaching to show why not everything should be inherited. Shapes are just too different for this.