Adding a Second Object - C++ Class

C++ examples for Class:Member Field

Description

Adding a Second Object

Demo Code

#include <cinttypes>
#include <iostream>

using namespace std;

class Car//from   w w  w . j av a  2  s  . c o  m
{
public:
    int m_NumberOfWheels;
};

int main(int argc, char* argv[])
{
    Car myCar;
    myCar.m_NumberOfWheels = 4;

    cout << "Number of wheels: " << myCar.m_NumberOfWheels << endl;

    Car myMotorcycle;
    myMotorcycle.m_NumberOfWheels = 2;

    cout << "Number of wheels: " << myMotorcycle.m_NumberOfWheels << endl;

    return 0;
}

Result


Related Tutorials