Advertisement
#include<iostream>
using namespace std;
class A
{
public:
int a = 10; //declaring a data member of class named 'a' of type int
void message(); //declaration of the function named 'message()'
};
//Definition of the function 'message' of class A, which returns void
void A :: message()
{
cout<< "Hello from the class A";
}
int main()
{
A ob; //Creating an object of class A
//Accessing the data member 'a' of the object of class A, with the dot operator
cout<< "The value of a : " << ob.a << "\n";
//Calling the function 'message' of the object of class A, with the dot operator.
ob.message();
}
class A
{
public:
int a = 10; //declaring a data member of class named 'a' of type int
void message(); //declaration of the function named 'message()'
};
//Definition of the function 'message' of class A, which returns void
void A :: message()
{
cout<< "Hello from the class A";
}
int main()
{
A ob; //Creating an object of class A
//Accessing the data member 'a' of the object of class A, with the dot operator
cout<< "The value of a : " << ob.a << "\n";
//Calling the function 'message' of the object of class A, with the dot operator.
ob.message();
}
Advertisement
D:\>g++ A.cpp -o A.exe
D:\>A.exe
The value of a : 10
Hello from the class A
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement