UMBC CMSC 211

UMBC | CSEE


Other C++ Features

Default Parameters

C++ allows a function to be declared with one or more parameters omitted, and gives them a default value:
int fun( int a, float b = 2.3, char c = 'x' );
  
Then the program can have:
fun( n, 3.14159 );
  
The compiler keeps a symbol table where it collects all of the necessary information and when one parameter is missing, it provides the value automatically, in this case with a:
push   'x'  
  

Overloaded Functions

Since the function name can appear with different parameter types, the compiler creates a unique name (name mangling):
declaration name/typereturnparams suffix
void f( ) ?f@@YA X X Z
void f( float ) ?f@@YA X M @Z
void f( float, float ) ?f@@YA X MM @Z
void f( int ) ?f@@YA X H @Z
int f( char ) ?f@@YA H D @Z
void f( int& ) ?f@@YA X AAH @Z
void f( int&, int& ) ?f@@YA X AAH0 @Z
void f( int&, int&, int& ) ?f@@YA X AAH00 @Z
void f( char &, int & ) ?f@@YA H AADAAH @Z

Polymorphic Call of Virtual Functions

This allows determining at run time what the data types of the argument are and the correct version of the function is called.


UMBC | CSEE