Object Oriented Programming: Elhanan Borenstein Borens@tau - Ac.il
Object Oriented Programming: Elhanan Borenstein Borens@tau - Ac.il
Programming
Elhanan Borenstein
[email protected]
Books
Object Oriented Programming and C++ / Amir Kirsh
The C++ Programming Lnaguage / Bjarne Stroustrup
Effective C++, More Effective C++ / Scott Meyeres
void printReallyNice(char*
It is still str,value
possible to give a different int fontSize = 10,
when calling thechar color
function (all = 0);
previous arguments must be specified too).
Arguments order
Default values are defined in the function prototype !!! (use a comment
notation in the implementation)
Beware Ambiguity!!!!
Argument in C++
In C++, arguments are still passed by Value, but
A function can ask to get an argument by reference (ByRef).
By reference arguments are in fact implemented with pointers, but hiding
them from the user a safer method!!!
Example: Find()
void main( )
{
int i = 23;
char *str = hello;
cout<<str;
cout<<i<<endl;
void main( )
{
int age;
char str[100];
The solution
Inline functions. The functions are embedded within
the call.
The compiler is not bound by the inline declaration.
copyrights Elhanan Borenstein
Memory Allocation
Allocation
Memory allocation is implemented with the command new.
No casting is required (unlike C).
For arrays allocation we will use new[n].
Freeing
To free allocated memory, we will use the command
delete.
For arrays, we will use delete[].
/* this is a comment */
// initialization
int index; // this is also a comment