VC++ tutorial

Visual C++ Examples

How To Add Menu In VC++

Classes In VC++
Previous Home Next

A class is an organization of data and functions which operate on them. Data structures are called data members and the functions are called member functions, The combination of data members and member functions constitute a data object or simply an object.

class consists of data members and methods. A member function determine the behavior of the class.


Class class_name
    Data Members;


#include <iostream> 
using namespace std;
class Box
double length; 
double breadth; 
double height; 
int main( )
Box Box1; 
 double volume = 0.0; 
Box1.height = 10; 
Box1.length = 5; 
Box1.breadth = 7;
volume = Box1.height * Box1.length * Box1.breadth;
cout << "Volume of Box1 : " << volume <<endl; 
return 0;

Access Specifiers:

public: If a class member is public, it can be used anywhere without the access restrictions.

#include <iostream>

using namespace std;

class Employee


  char name;
  int salary;

int main()
    Employee obj;

    cout<<"Enter the Name :";

    cout<<"Enter the salary :";

    cout << << ": " << obj.salary << endl;

    return 0;

private: If a class member is private, it can be used only by the members and friends of class.

protcted: If a class member is protected, it can be used only by the members and friends of class and the members and friends of classes derived from class.

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Comment / Feedback: