C++ Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 





Class in C++


Tutorials Cpp

Topic

Using class in C++?



Explanation

A Class is a way to bind the data and its associated functions together. All the elements of a class are private by default, even elements can be declared as public or protected. An object is an instance of a class.

Syntax:
   class class-name{
       access:specifier
       private data and functions
       }

In the above syntax the every class has a unique name, the "access:specifier" can either private, public, protected. The "protected" is used when inhertinace is applied.

Example:

   #include <iostream.h>
   class dat
    {
     private:
       int sdata;
     public: 
       void setdat( int a)
          {  sdata =a; }
       void show( )
        { cout << "\nSet data is " << sdata;}
    };
   void main()
    {
       dat x,y;
       x.setdat(1000);
       y.setdat(1245);
     
       x.show();
       y.show();
    }

Result:
   Set Data is:1000
   Set Data is:1245

In the above class example the "private" object "sdata" is used only within the function. But the functions "setdat", "show" are used in the main function since they are "public".










Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting