Inheritance best practice : *args, **kwargs or explicitly specifying parameters [closed]

Liskov Substitution Principle Generally you don’t want you method signature to vary in derived types. This can cause problems if you want to swap the use of derived types. This is often referred to as the Liskov Substitution Principle. Benefits of Explicit Signatures At the same time I don’t think it’s correct for all your … Read more

Why can’t two methods be declared with the same signature even though their return types are different? [duplicate]

It’s because of type coercion. Say you have the following functions: int x(double); float x(double); double y = x(1.0); Now, which of the two prototypes should you call, especially if they do two totally different things? Basically, a decision was made early on in the language design to only use the function name and arguments … Read more

How to return an array from a function?

int* test(); but it would be “more C++” to use vectors: std::vector< int > test(); EDIT I’ll clarify some point. Since you mentioned C++, I’ll go with new[] and delete[] operators, but it’s the same with malloc/free. In the first case, you’ll write something like: int* test() { return new int[size_needed]; } but it’s not … Read more