Adding Data to a Class - C++ Class

C++ examples for Class:Member Field

Introduction

The Car Class with a Member Variable

Demo Code

#include <cinttypes>
#include <iostream>

using namespace std;

class Car//from w  w w. ja  v a 2s .c  om
{
public:
    int m_NumberOfWheels;
};

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

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

    return 0;
}

Result


Related Tutorials