18-06-2013, 04:01 PM
Limitations of Structures in C
Limitations of Structures.pptx (Size: 151.46 KB / Downloads: 15)
Introduction
In C structures are used to combine one or more data types
Functions are not permitted
Objects can access the data members of the structures directly
Outside function can also access the data members of the structure through the object
In C++ structure also combine structure with data members
C++ introduces a new keyword ‘Class’
Limitations of Structures in C
Only variables of different data types can be declared, functions are not allowed
Direct access to data members is possible
‘struct’ data type is not treated as built in type – use of ‘struct’ necessary to declare objects
Member variables cannot be initialized inside a structure
Structures in C++
In C++ structure declaration functions can also be declared
The members declared in a C++ structure is public by default
While declaring an object the keyword ‘struct’ is omitted in C++
Classes in C++
Classes and structure are the same with only a small difference
For OO Programming classes are used and not structure
Class is used to put together data and functions
Class has a mechanism to prevent direct access to its members (central OOP idea)
Defining Member Functions
Member function must be declared inside the class
They can be defined in:
Private or Public section
Inside or Outside the class
Member function defined inside the class are treated as inline function
Member function which are small should be defined inside the class
Member Functions
What about member functions?
Member functions are created and memory is allocated to them only once when a class is declared
All objects of a class access the same memory location where member functions are stored
Separate copies of member functions are not present in every object like member variables