Skip to end of metadata
Go to start of metadata

This task was to demonstrate various examples of functions and their abilities. I overload a function, override a function, and use a function with variable number of arguments.


How do you define the return type of a function? Must all functions have a return value or type?

You define it before the function's name. You have to return a value or void. You can return pointers like in C, too.

Can you overload functions in your language? If so, what are the rules for differentiating overloaded functions?

You can . We can overload a function with a different number of argument, different type of argument, ellipses, and const or volatile (used to prevent optimization).

Can you create functions with an unknown number of arguments? How do you access those arguments?

To use any number of arguments, we use ... after also specifying an argument that represents how many come after it. We need to make a list of the current arguments with va_list, initialize them with va_start, and clean up the list at the end with va_end.

Can you dynamically create functions? If so, how?

It is doable but very difficult. You could either choose different premade functions depending on the input, or write a program into a file, use a different compilation command, and load the program dynamically.

Can you override functions with a new definition?

Yes. We override a function by declaring the derived class's name as derivedClass:public baseClass.

What mechanism exists for publishing the existence of a function to other functions or compilable units (e.g. files)?

Using a header file.


  • No labels