Class and Structure in C++
Difference
|
Class
|
Structure
|
Definition
|
A class
in C++ can be defined as a collection of related variables and functions
encapsulated in a single structure.
|
A
structure can be referred to as a user defined data type possessing its own
operations.
|
Keyword
for the declaration
|
Class
|
Struct
|
Default
access specifier
|
Private
|
Public
|
Example
|
class
myclass
{
private:
int data;
public:
myclass(int data_):
data(data_)
{}
virtual void foo()=0;
virtual ~class()
{}
};a
|
struct
myclass
{
private:
int data;
public:
myclass(int data_):
data(data_)
{}
virtual void foo()=0;
virtual ~class()
{}
};
|
Purpose
|
Data
abstraction and further inheritance
|
Generally,
grouping of data
|
Type
|
Reference
|
Value
|
Usage
|
Generally
used for large amounts of data.
|
Generally
used for smaller amounts of data.
|
loading...
No comments: