Objectives
- Structures : contains aggregated data-types
- A struct differs from a class, by having all members
are declared as public; whereas the default scopes of the
members of a class are private.
- sturct can be initialized few different ways.
- (a) myStruct ms;
ms.strructmem1 = 1234; // using a dot operator
ms.structmem2 = 10;
- (b) mystruct ms2 = { 1234, 10 }; // which should
correspond the orders of
(c) struct constructor
struct mystruct
{
double d1, d2;
mystruct() : d1(0,0), d2(0,0) {} // default constructor
mystruct( double d3, double d4): d1(d1value1),
d2(d2value1){}
};
- Unlike an arrray , struct can contain heterogeneous (
different data type)
- Code
testMyStruct1.txt
|