// classes.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include #include using namespace std; class MyClass // "class" followed by the name of the class { // open brace protected: // protected specification: like "private" // except subclasses have direct access. private: // private specification: // write data members and/or functions // that are visible only inside an object int val; // example of a data member public: // public specification: // write data members (rare) and functions // accessible directly from the object. int get_val(); // example of a member // function declaration MyClass(int data); // declaration of class constructor ~MyClass(); // declaration of class destructor }; // close brace AND semicolon int MyClass::fn(){return val;} // member function defined outside MyClass::MyClass(int data){val = data;} // constructor definition MyClass::~MyClass(){} // destructor definition int _tmain(int argc, _TCHAR* argv[]) { MyClass newobject(4); int a = newobject.get_val(); cout << a << endl; return 0; }