Sei sulla pagina 1di 39

Submitted By : Submitted to :

Soniya

INDEX

Page 1
INDEX

S.No Particular Page No

1 Operator Overloading 3-4

2 Operator Precedence 5-6

3 Control Statement
7-19

4 Function in C++ 20-25

5 Function Overloading 26-29

6 Friend Function in C++ 30-34

7 Virtual Function in C++ 35-39

Page 2
Operator Overloading
Same operator but different behaviour is called operator overloading. In
other words , Operator overloading is a technique by
which operators used in a programming language are implemented in
user-defined types with customized logic that is based on the types of
arguments passed.
Almost all the operators can be overloaded in infinite different ways.
Following are some examples to learn more about operator overloading.
All the examples are closely connected.

Overloading Arithmetic Operator


Arithmetic operator are most commonly used operator in C++. Almost all
arithmetic operator can be overloaded to perform arithmetic operation on
user-defined data type. In the below example we have overridden
the + operator, to add to Time(hh:mm:ss) objects.
Example: overloading '+' Operator to add two time object
#include< iostream.h>
#include< conio.h>
class time
{
int h,m,s;
public:
time()
{
h=0, m=0; s=0;
}
void getTime();
void show()
{
cout<< h<< ":"<< m<< ":"<< s;
}
time operator+(time); //overloading '+' operator
};
time time::operator+(time t1) //operator function
{
time t;

Page 3
int a,b;
a=s+t1.s;
t.s=a%60;
b=(a/60)+m+t1.m;
t.m=b%60;
t.h=(b/60)+h+t1.h;
t.h=t.h%12;
return t;
}
void time::getTime()
{
cout<<"\n Enter the hour(0-11) ";
cin>>h;
cout<<"\n Enter the minute(0-59) ";
cin>>m;
cout<<"\n Enter the second(0-59) ";
cin>>s;
}
void main()
{
clrscr();
time t1,t2,t3;
cout<<"\n Enter the first time ";
t1.getTime();
cout<<"\n Enter the second time ";
t2.getTime();
t3=t1+t2; //adding of two time object using '+' operator
cout<<"\n First time ";
t1.show();
cout<<"\n Second time ";
t2.show();
cout<<"\n Sum of times ";
t3.show();
getch();
}

*****************

Page 4
Operator Precedence
Definition: Precedence is the order in which a program performs the
operations in a formula. If one operator has precedence over another
operator, it is evaluated first.

Operator Precedence.
Rank Name Operator
1 scope resolution ::
2 member selection, subscripting, . ->
function calls, postfix increment ()
and decrement ++ --
3 sizeof, prefix increment and decrement, ++ --
complement, and, not, unary minus and plus, ^!
address of and dereference, new, new[],
-+
delete,
delete[], casting, sizeof(), &*
()
4 member selection for pointer .* ->*
5 multiply, divide, modulo */%
6 add, subtract +-
7 shift << >>
8 inequality relational < <= > >=
9 equality, inequality == !=
10 bitwise AND &
11 bitwise exclusive OR ^
12 bitwise OR |
13 logical AND &&
14 logical OR ||

Page 5
15 conditional ?:
16 assignment operators = *= /= %=
+= -= <<=
>>=
&= |= ^=
17 throw operator throw
18 comma ,

*****************

Page 6
Control Statement/Control Structures
Control statements enable us to specify the flow of program control; ie,
the order in which the instructions in a program must be executed. They
make it possible to make decisions, to perform tasks repeatedly or to jump
from one section of code to another. Following are the type of control
statement.

1. If statement
2. Switch case statement

If statement :-
An if statement is a programming conditional statement that, if proved
true, performs a function or displays information. Below is a general
example of an if statement, not specific to any particular programming
language.
Types of If statement :-
1. Simple if statement
2. If else statement
3. Nested if statement
4. Else if statement

If statement
Syntax
if (testExpression)
{
// statements
}

The if statement evaluates the test expression inside parenthesis.

If test expression is evaluated to true (nonzero), statements inside the body


of if is executed.

If test expression is evaluated to false (0), statements inside the body


of if is skipped.

Page 7
Flowchart of if statement

Example #1: C if statement


// Program to display a number if user enters negative number
// If user enters positive number, that number won't be displayed

#include <stdio.h>
int main()
{
int number;

printf("Enter an integer: ");


scanf("%d", &number);

// Test expression is true if number is less than 0


if (number < 0)

Page 8
{
printf("You entered %d.\n", number);
}

printf("The if statement is easy.");

return 0;
}

Output 1
Enter an integer: -2
You entered -2.
The if statement is easy.

When user enters -2, the test expression (number < 0) becomes true.
Hence, You entered -2 is displayed on the screen.

Output 2
Enter an integer: 5
The if statement in C programming is easy.

When user enters 5, the test expression (number < 0) becomes false and
the statement inside the body of if is skipped.
If...else statement

The if...else statement executes some code if the test expression is true
(nonzero) and some other code if the test expression is false (0).
Syntax of if...else
if (testExpression) {
// codes inside the body of if
}
else {
// codes inside the body of else
}

If test expression is true, codes inside the body of if statement is executed


and, codes inside the body of else statement is skipped.

Page 9
If test expression is false, codes inside the body of else statement is
executed and, codes inside the body of if statement is skipped.

Flowchart of if...else statement

Example #2: C if...else statement


// Program to check whether an integer entered by the user is odd or even

#include <stdio.h>
int main()
{
int number;
printf("Enter an integer: ");
scanf("%d",&number);

// True if remainder is 0

Page
10
if( number%2 == 0 )
printf("%d is an even integer.",number);
else
printf("%d is an odd integer.",number);
return 0;
}

Output
Enter an integer: 7
7 is an odd integer.

When user enters 7, the test expression ( number%2 == 0 ) is evaluated to


false. Hence, the statement inside the body of else statement printf("%d is
an odd integer"); is executed and the statement inside the body of if is
skipped.

Nested if...else statement (if...elseif....else Statement)

The if...else statement executes two different codes depending upon


whether the test expression is true or false. Sometimes, a choice has to be
made from more than 2 possibilities.

The nested if...else statement allows you to check for multiple test
expressions and execute different codes for more than two conditions.

Syntax of nested if...else statement.


if (testExpression1)
{
// statements to be executed if testExpression1 is true
}
else if(testExpression2)
{
// statements to be executed if testExpression1 is false and
testExpression2 is true
}
else if (testExpression 3)
{

Page
11
// statements to be executed if testExpression1 and testExpression2 is
false and testExpression3 is true
}
.
.
else
{
// statements to be executed if all test expressions are false
}
Example #3: C Nested if...else statement
// Program to relate two integers using =, > or <

#include <stdio.h>
int main()
{
int number1, number2;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);

//checks if two integers are equal.


if(number1 == number2)
{
printf("Result: %d = %d",number1,number2);
}

//checks if number1 is greater than number2.


else if (number1 > number2)
{
printf("Result: %d > %d", number1, number2);
}

// if both test expression is false


else
{
printf("Result: %d < %d",number1, number2);
}

return 0;
}

Page
12
Output
Enter two integers: 12
23
Result: 12 < 23

Switch Case Statement

Loop
Loops are used in programming to repeat a specific block of code

Loops are used in programming to repeat a specific block until some end
condition is met. There are three loops in C programming:

1. for loop
2. while loop
3. do...while loop
For Loop

The syntax of for loop is:


for (initializationStatement; testExpression; updateStatement)
{
// codes
}
How for loop works?

The initialization statement is executed only once.

Then, the test expression is evaluated. If the test expression is false (0), for
loop is terminated. But if the test expression is true (nonzero), codes inside
the body of for loop is executed and the update expression is updated.

This process repeats until the test expression is false.

The for loop is commonly used when the number of iterations is known.

To learn more on test expression (when test expression is evaluated to


nonzero (true) and 0 (false)), check out relational and logical operators.

Page
13
For loop Flowchart

Example: for loop

// Program to calculate the sum of first n natural numbers


// Positive integers 1,2,3...n are known as natural numbers

#include <stdio.h>
int main()
{
int num, count, sum = 0;

printf("Enter a positive integer: ");


scanf("%d", &num);

Page
14
// for loop terminates when n is less than count
for(count = 1; count <= num; ++count)
{
sum += count;
}

printf("Sum = %d", sum);

return 0;
}

Output
Enter a positive integer: 10
Sum = 55

The value entered by the user is stored in variable num. Suppose, the user
entered 10.

The count is initialized to 1 and the test expression is evaluated. Since, the
test expression count <= num (1 less than or equal to 10) is true, the body
of for loop is executed and the value of sum will equal to 1.

Then, the update statement ++count is executed and count will equal to 2.
Again, the test expression is evaluated. Since, 2 is also less than 10, the
test expression is evaluated to true and the body of for loop is executed.
Now, the sum will equal 3.

This process goes on and the sum is calculated until the count reaches 11.

When the count is 11, the test expression is evaluated to 0 (false) as 11 is


not less than or equal to 10. Therefore, the loop terminates and next, the
total sum is printed.
While loop

The syntax of a while loop is:


while (testExpression)
{
//codes
}

Page
15
How while loop works?

The while loop evaluates the test expression.

If the test expression is true (nonzero), codes inside the body of while loop
is evaluated. The test expression is evaluated again. The process goes on
until the test expression is false.

When the test expression is false, the while loop is terminated.

Flowchart of while loop

Example #1: while loop


// Program to find factorial of a number
// For a positive integer n, factorial = 1*2*3...n

#include <stdio.h>
int main()
{
int number;
long long factorial;

Page
16
printf("Enter an integer: ");
scanf("%d",&number);

factorial = 1;

// loop terminates when number is less than or equal to 0


while (number > 0)
{
factorial *= number; // factorial = factorial*number;
--number;
}

printf("Factorial= %lld", factorial);

return 0;
}

Output
Enter an integer: 5
Factorial = 120

To learn more on test expression (when test expression is evaluated to


nonzero (true) and 0 (false)), check out relational and logical operators.
Do...while loop

The do..while loop is similar to the while loop with one important
difference. The body of do...while loop is executed once, before checking
the test expression. Hence, the do...while loop is executed at least once.

do...while loop Syntax


do
{
// codes
}
while (testExpression);

Page
17
How do...while loop works?

The code block (loop body) inside the braces is executed once.

Then, the test expression is evaluated. If the test expression is true, the
loop body is executed again. This process goes on until the test expression
is evaluated to 0 (false).

When the test expression is false (nonzero), the do...while loop is


terminated.

Example #2: do...while loop


// Program to add numbers until user enters zero

#include <stdio.h>
int main()
{
double number, sum = 0;

// loop body is executed at least once

Page
18
do
{
printf("Enter a number: ");
scanf("%lf", &number);
sum += number;
}
while(number != 0.0);

printf("Sum = %.2lf",sum);

return 0;
}

Output
Enter a number: 1.5
Enter a number: 2.4
Enter a number: -3.4
Enter a number: 4.2
Enter a number: 0
Sum = 4.70

*******************

Page
19
Function in C ++

A function is a group of statements that together perform a task. Every


C++ program has at least one function, which is main(), and all the most
trivial programs can define additional functions.
You can divide up your code into separate functions. How you divide up
your code among different functions is up to you, but logically the
division usually is so each function performs a specific task.
A function declaration tells the compiler about a function's name, return
type, and parameters. A function definition provides the actual body of
the function.
The C++ standard library provides numerous built-in functions that your
program can call. For example, function strcat() to concatenate two
strings, function memcpy() to copy one memory location to another
location and many more functions.
Different programming languages name functions differently like a
method or a sub-routine or a procedure etc.
Defining a Function
The general form of a C++ function definition is as follows:

return_type function_name( parameter list ) {


body of the function
}
A C++ function definition consists of a function header and a function
body. Here are all the parts of a function:
Return Type: A function may return a value. The return_type is
the data type of the value the function returns. Some functions
perform the desired operations without returning a value. In this
case, the return_type is the keyword void.
Function Name: This is the actual name of the function. The
function name and the parameter list together constitute the function
signature.
Parameters: A parameter is like a placeholder. When a function is
invoked, you pass a value to the parameter. This value is referred to
as actual parameter or argument. The parameter list refers to the
type, order, and number of the parameters of a function. Parameters
are optional; that is, a function may contain no parameters.

Page
20
Function Body: The function body contains a collection of
statements that define what the function does.
Example
Following is the source code for a function called max(). This function
takes two parameters num1 and num2 and returns the maximum between
the two:
// function returning the max between two numbers

int max(int num1, int num2) {


// local variable declaration
int result;

if (num1 > num2)


result = num1;
else
result = num2;

return result;
}
Function Declarations
A function declaration tells the compiler about a function name and how
to call the function. The actual body of the function can be defined
separately.
A function declaration has the following parts:
return_type function_name( parameter list );
For the above defined function max(), following is the function
declaration:
int max(int num1, int num2);
Parameter names are not importan in function declaration only their type
is required, so following is also valid declaration:
int max(int, int);
Function declaration is required when you define a function in one source
file and you call that function in another file. In such case, you should
declare the function at the top of the file calling the function.
Calling a Function
While creating a C++ function, you give a definition of what the function
has to do. To use a function, you will have to call or invoke that function.

Page
21
When a program calls a function, program control is transferred to the
called function. A called function performs defined task and when its
return statement is executed or when its function-ending closing brace is
reached, it returns program control back to the main program.
To call a function, you simply need to pass the required parameters along
with function name, and if function returns a value, then you can store
returned value. For example:
#include <iostream>
using namespace std;

// function declaration
int max(int num1, int num2);

int main () {
// local variable declaration:
int a = 100;
int b = 200;
int ret;

// calling a function to get max value.


ret = max(a, b);

cout << "Max value is : " << ret << endl;

return 0;
}

// function returning the max between two numbers


int max(int num1, int num2) {
// local variable declaration
int result;

if (num1 > num2)


result = num1;
else
result = num2;

return result;

Page
22
}
I kept max() function along with main() function and compiled the source
code. While running final executable, it would produce the following
result:
Max value is : 200
Function Arguments
If a function is to use arguments, it must declare variables that accept the
values of the arguments. These variables are called the formal
parameters of the function.
The formal parameters behave like other local variables inside the
function and are created upon entry into the function and destroyed upon
exit.
While calling a function, there are two ways that arguments can be passed
to a function:
Call Type Description

Call by value This method copies the actual value of an


argument into the formal parameter of the
function. In this case, changes made to the
parameter inside the function have no effect on
the argument.

Call by pointer This method copies the address of an argument


into the formal parameter. Inside the function, the
address is used to access the actual argument used
in the call. This means that changes made to the
parameter affect the argument.

Call by reference This method copies the reference of an argument


into the formal parameter. Inside the function, the
reference is used to access the actual argument
used in the call. This means that changes made to
the parameter affect the argument.
By default, C++ uses call by value to pass arguments. In general, this
means that code within a function cannot alter the arguments used to call

Page
23
the function and above mentioned example while calling max() function
used the same method.
Default Values for Parameters
When you define a function, you can specify a default value for each of
the last parameters. This value will be used if the corresponding argument
is left blank when calling to the function.
This is done by using the assignment operator and assigning values for
the arguments in the function definition. If a value for that parameter is
not passed when the function is called, the default given value is used, but
if a value is specified, this default value is ignored and the passed value is
used instead. Consider the following example:
#include <iostream>
using namespace std;

int sum(int a, int b=20) {


int result;

result = a + b;

return (result);
}

int main () {
// local variable declaration:
int a = 100;
int b = 200;
int result;

// calling a function to add the values.


result = sum(a, b);
cout << "Total value is :" << result << endl;

// calling a function again as follows.


result = sum(a);
cout << "Total value is :" << result << endl;

return 0;
}

Page
24
When the above code is compiled and executed, it produces the following
result:
Total value is :300
Total value is :120

*****************

Page
25
Function Overloading

C++ allows specification of more than one function of the same name in
the same scope. These are called overloaded functions and are described in
detail in Overloading. Overloaded functions enable programmers to supply
different semantics for a function, depending on the types and number of
arguments.
For example, a print function that takes a string (or char *) argument
performs very different tasks than one that takes an argument of
type double. Overloading permits uniform naming and prevents
programmers from having to invent names such as print_sz or print_d. The
following table shows what parts of a function declaration C++ uses to
differentiate between groups of functions with the same name in the same
scope.

Overloading Considerations

Function Declaration Element Used for Overloading?

Function return type No

Number of arguments Yes

Type of arguments Yes

Presence or absence of ellipsis Yes

Use of typedef names No

Unspecified array bounds No

Page
26
Function Declaration Element Used for Overloading?

const or volatile (see below) Yes

Although functions can be distinguished on the basis of return type, they


cannot be overloaded on this basis. Const or volatile are only used as a
basis for overloading if they are used in a class to apply to the this pointer
for the class, not the function's return type. In other words, overloading
applies only if the const or volatile keyword follows the function's
argument list in the declaration.

Example
The following example illustrates how overloading can be used

// function_overloading.cpp
// compile with: /EHsc
#include <iostream>
#include <math.h>

// Prototype three print functions.


int print( char *s ); // Print a string.
int print( double dvalue ); // Print a double.
int print( double dvalue, int prec ); // Print a double with a
// given precision.
using namespace std;
int main( int argc, char *argv[ ] )
{
const double d = 893094.2987;
if( argc < 2 )
{
// These calls to print invoke print( char *s ).
print( "This program requires one argument." );
print( "The argument specifies the number of" );
print( "digits precision for the second number" );
print( "printed." );
exit(0);
}

Page
27
// Invoke print( double dvalue ).
print( d );

// Invoke print( double dvalue, int prec ).


print( d, atoi( argv[1] ) );
}

// Print a string.
int print( char *s )
{
cout << s << endl;
return cout.good();
}

// Print a double in default precision.


int print( double dvalue )
{
cout << dvalue << endl;
return cout.good();
}

// Print a double in specified precision.


// Positive numbers for precision indicate how many digits
// precision after the decimal point to show. Negative
// numbers for precision indicate where to round the number
// to the left of the decimal point.
int print( double dvalue, int prec )
{
// Use table-lookup for rounding/truncation.
static const double rgPow10[] = {
10E-7, 10E-6, 10E-5, 10E-4, 10E-3, 10E-2, 10E-1, 10E0,
10E1, 10E2, 10E3, 10E4, 10E5, 10E6
};
const int iPowZero = 6;
// If precision out of range, just print the number.
if( prec < -6 || prec > 7 )
return print( dvalue );
// Scale, truncate, then rescale.
dvalue = floor( dvalue / rgPow10[iPowZero - prec] ) *

Page
28
rgPow10[iPowZero - prec];
cout << dvalue << endl;
return cout.good();
}

The preceding code shows overloading of the print function in file scope.
The default argument is not considered part of the function type.
Therefore, it is not used in selecting overloaded functions. Two functions
that differ only in their default arguments are considered multiple
definitions rather than overloaded functions.

*****************

Page
29
FRIEND FUNCTION IN C++

If a function is defined as a friend function then, the private and protected


data of a class can be accessed using the function.

The complier knows a given function is a friend function by the use of the
keyword friend.

For accessing the data, the declaration of a friend function should be made
inside the body of the class (can be anywhere inside class either in private
or public section) starting with keyword friend.
Declaration of friend function in C++

class class_name
{
... .. ...
friend return_type function_name(argument/s);
... .. ...
}

Now, you can define the friend function as a normal function to access the
data of the class. No friend keyword is used in the definition.
class className
{
... .. ...
friend return_type functionName(argument/s);
... .. ...
}

return_type functionName(argument/s)
{
... .. ...
// Private and protected data of className can be accessed from
// this function because it is a friend function of className.
... .. ...
}

Page
30
Example 1: Working of friend Function

/* C++ program to demonstrate the working of friend function.*/


#include <iostream>
using namespace std;

class Distance
{
private:
int meter;
public:
Distance(): meter(0) { }
//friend function
friend int addFive(Distance);
};

// friend function definition


int addFive(Distance d)
{
//accessing private data from non-member function
d.meter += 5;
return d.meter;
}

int main()
{
Distance D;
cout<<"Distance: "<< addFive(D);
return 0;
}

Output
Distance: 5

Here, friend function addFive() is declared inside Distance class. So, the
private data meter can be accessed from this function.

Page
31
Though this example gives you an idea about the concept of a friend
function, it doesn't give show you any meaningful use.

A more meaningful use would to when you need to operate on objects of


two different classes. That's when the friend function can be very helpful.

You can definitely operate on two objects of different classes without


using the friend function but the program will be long, complex and hard
to understand.
Example 2: Addition of members of two different classes using friend
Function

#include <iostream>
using namespace std;

// forward declaration
class B;
class A {
private:
int numA;
public:
A(): numA(12) { }
// friend function declaration
friend int add(A, B);
};

class B {
private:
int numB;
public:
B(): numB(1) { }
// friend function declaration
friend int add(A , B);
};

// Function add() is the friend function of classes A and B


// that accesses the member variables numA and numB
int add(A objectA, B objectB)
{

Page
32
return (objectA.numA + objectB.numB);
}

int main()
{
A objectA;
B objectB;
cout<<"Sum: "<< add(objectA, objectB);
return 0;
}

Output
Sum: 13

In this program, classes A and B have declared add() as a friend function.


Thus, this function can access private data of both class.

Here, add() function adds the private data numA and numB of two
objects objectA and objectB, and returns it to the main function.

To make this program work properly, a forward declaration of a class class


B should be made as shown in the above example.

This is because class B is referenced within the class A using code: friend
int add(A , B);.

friend Class in C++ Programming

Similarly, like a friend function, a class can also be made a friend of


another class using keyword friend. For example:
... .. ...
class B;
class A
{
// class B is a friend class of class A
friend class B;
... .. ...
}

Page
33
class B
{
... .. ...
}

When a class is made a friend class, all the member functions of that class
becomes friend functions.

In this program, all member functions of class B will be friend functions


of class A. Thus, any member function of class B can access the private
and protected data of class A. But, member functions of class A cannot
access the data of class B.

Remember, friend relation in C++ is only granted, not taken.

*******************

Page
34
Virtual Function in C++

A virtual function is a member function in base class that you expect to


redefine in derived classes.

Before going into detail, let's build an intuition on why virtual functions
are needed in the first place.
Example

Let us assume, we are working on a game (weapons specifically).

We created the Weapon class and derived two classes Bomb and Gun to
load features of respective weapons.
#include <iostream>
using namespace std;

class Weapon
{
public:
void loadFeatures()
{ cout << "Loading weapon features.\n"; }
};

Page
35
class Bomb : public Weapon
{
public:
void loadFeatures()
{ cout << "Loading bomb features.\n"; }
};

class Gun : public Weapon


{
public:
void loadFeatures()
{ cout << "Loading gun features.\n"; }
};

int main()
{
Weapon *w = new Weapon;
Bomb *b = new Bomb;
Gun *g = new Gun;

w->loadfeatures();
b->loadFeatures();
g->loadFeatures();

return 0;
}

Output
Loading weapon features.
Loading bomb features.
Loading gun features.

We defined three pointer objects w, b and g of


classes Weapon, Bomb and Gunrespectively. And, we
called loadFeatures() member function of each objects using:
w->loadfeatures();
b->loadFeatures();
g->loadFeatures();

Works perfectly!

Page
36
However, our game project started getting bigger and bigger. And, we
decided to create a separate Loader class to load weapon features.

This Loader class loads additional features of a weapon depending on


which weapon is selected.

class Loader
{
public:
void loadFeatures(Weapon *weapon)
{
weapon->features();
}
};

The loadFeatures() loads the feature of a specific weapon.


Let's try to implement our Loader class

#include <iostream>
using namespace std;

class Weapon
{
public:
void features()
{ cout << "Loading weapon features.\n"; }
};

class Bomb : public Weapon


{
public:
void features()
{ cout << "Loading bomb features.\n"; }
};

class Gun : public Weapon


{
public:
void features()

Page
37
{ cout << "Loading gun features.\n"; }
};

class Loader
{
public:
void loadFeatures(Weapon *weapon)
{
weapon->features();
}
};

int main()
{
Loader *l = new Loader;
Weapon *w;
Bomb b;
Gun g;

w = &b;
l->loadFeatures(w);

w = &g;
l->loadFeatures(w);

return 0;
}

Output
Loading weapon features.
Loading weapon features.
Loading weapon features.

Our implementation seemed correct. However, weapon features was


loaded 3 times. Why?

Initially, the Weapon object w is pointing to the b object (of Bomb) class.
And, we tried to load the features of Bomb object by passing it
to loadFeatures() function using l object to pointer (of Loader class).

Similarly, we tried to load the features of Gun object.

Page
38
However, the loadFeatures() function of the Loader class takes pointer to
object of a Weapon class as an argument:
void loadFeatures(Weapon *weapon)

That's the reason weapon features are loaded 3 times. To solve this issue,
we need to make function of base class (Weapon class) virtual using
virtual keyword.
class Weapon
{
public:
virtual void features()
{ cout << "Loading weapon features.\n"; }
};

******************

Page
39

Potrebbero piacerti anche