Classes and Objects: C++ 6 Sem, A' Div 2018-19 Ms. Mouna M. Naravani

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Chapter 2

Classes and Objects

C++
6th Sem, ‘A’ Div
2018-19
Ms. Mouna M. Naravani
Access Specifiers

• Private

• Public

• Protected
Scope Resolution Operator ( :: )

• Major application of scope resolution operator is to define member


functions outside the class.

• This helps to identify the class to which a member function belong.


• W. k. t. same variable name can be used to have different meanings in
different blocks.

• Blocks in C++ are often nested.

• Block 2 is contained in Block 1.


• Declaration in inner block hides
the declaration of same variable in
outer block.
• In C, the global version of a variable cannot be accessed from within the
inner block.
• Guess the output of the following C code….
#include<stdio.h>
int g=10;
int main()
{
int g=30;
printf("Outer block g=%d\n", g);
{
printf("Inner block g=%d\n",g);
}
return 0;
}
• C++ resolves this problem by introducing a new operator :: called Scope
Resolution Operator.
• Syntax:
::variable-name
• This operator allows access to the global version of a variable.

This is one of
the difference
between C
and C++.

You might also like