C++ Learning Resource Network!

 
 C++ Tutorials  >  Object Oriented Programming  >  Structures Vs. Classes
 

Structures vs. Classes

The only difference between a structure and a class is that, in a class, the member data or function are private by default whereas, in a structure, they are public by default.

The following code segment:
Class demo
{
private:
int iNum1;
public:
void func(void);
};



can be written as:

class demo
{
int iNum1;
public:
void func(void);
};


The keyword private need not be mentioned because, in a class, the members are private by default.

The code segment can be modified using a structure in the following way:

Class demo
{
int iNum1;
public:
void func(void);
};

The keyword private need not be mentioned because, in a class, the members are private by default.

The code segment can be modified using a structure in the following way:
struct demo
{
void func(void);
private:
int iNum1;
};

The keyword public need not be mentioned because the structure members are public by default.
 

 

| Bookmark This Site |   | Links |   | Search |   | Submit |   | Contact |

  Copyright 2008 - 3008  CppTutor.com All rights reserved.