Check out example codes for "c++ classes". It will help you in understanding the concepts better.

Code Example 1

// C++ program to demonstrate function  
// declaration outside class 
  
#include <bits/stdc++.h> 
using namespace std; 
class Geeks 
{ 
    public: 
    string geekname; 
    int id; 
      
    // printname is not defined inside class definition 
    void printname(); 
      
    // printid is defined inside class definition 
    void printid() 
    { 
        cout << "Geek id is: " << id; 
    } 
}; 
  
// Definition of printname using scope resolution operator :: 
void Geeks::printname() 
{ 
    cout << "Geekname is: " << geekname;  
} 
int main() { 
      
    Geeks obj1; 
    obj1.geekname = "xyz"; 
    obj1.id=15; 
      
    // call printname() 
    obj1.printname(); 
    cout << endl; 
      
    // call printid() 
    obj1.printid(); 
    return 0; 
}

Code Example 2

// C++ program to demonstrate  
// accessing of data members  
  
#include <bits/stdc++.h> 
using namespace std; 
class Geeks 
{ 
    // Access specifier 
    public: 
  
    // Data Members 
    string geekname; 
  
    // Member Functions() 
    void printname() 
    { 
       cout << "Geekname is: " << geekname; 
    } 
}; 
  
int main() { 
  
    // Declare an object of class geeks 
    Geeks obj1; 
  
    // accessing data member 
    obj1.geekname = "Abhi"; 
  
    // accessing member function 
    obj1.printname(); 
    return 0; 
}

Code Example 3

class MyClass {       // The class
  public:             
  // Access specifier
    int myNum;        // 
  Attribute (int variable)
    string myString;  // 
  Attribute (string variable)
};

int main() {
  MyClass myObj;  
  // Create an object of MyClass

  // Access attributes and set values
  myObj.myNum 
  = 15; 
  
  myObj.myString = "Some text";

  // Print attribute values
  
  cout << myObj.myNum << "\n"; 
  cout << myObj.myString; 
  return 0;
}

Learn ReactJs, React Native from akashmittal.com