Once a class is declared and created, we can create the variables of that class type with the help of the class name. In C++, the variables of a class are known as objects.

Declaring an object is similar to declaring a variable of any basic data type. Once the object is declared, the memory space required for that object is allocated to it.

We can declare an object by placing them immediately after the close brackets of the class declaration and before the semicolon. 

We can also declare objects within the main() function. An object invokes its member functions using the dot operator.

How to Access Class Members Function in C++ program

using namespace std;
class MyClass{ public: void codeverb() { 
cout<<"Welcome to Codeverb"; } 
int main() { 
MyClass s;
return 0;

Output:-Welcome to Codeverb

Explanation of the program

In this program ‘s’ is an object of class type MyClass.codeverb() is a public member function of the class MyClass. The dot operator used i.e, s.codeverb()means ‘s’ accesses codeverb().

This article is written by our awesome writer
Comments to: How to Access Class Members Function In C++

Your email address will not be published. Required fields are marked *

Attach images - Only PNG, JPG, JPEG and GIF are supported.

New Dark Mode Is Here

Sign In to access the new Dark Mode reading option.

Join our Newsletter

Get our monthly recap with the latest news, articles and resources.

By subscribing you agree to our Privacy Policy.

Latest Articles

Explore Tutorials By Categories


Codeverb is simply an all in one interactive learning portal, we regularly add new topics and keep improving the existing ones, if you have any suggestions, questions, bugs issue or any other queries you can simply reach us via the contact page


Welcome to Codeverb

Ready to learn something new?
Join Codeverb!

Read Smart, Save Time
    Strength indicator
    Log In | Lost Password