The Basic of C + + Class
A simple class, that stored a data.
Key Points
1.include<iostream>
2.using namespace Std;
3.the function of the class is as followed:
1) Store a data
2) rewrite and read it
3) constructor using 0 as default data
4) or give a initial data in parameter
4.main:
1) int Main
2) return 0
3) Instance Object statement
4) Endl
5) System ("Pause")
//a simple class, that stored a data.#include"stdafx.h"#include<iostream>using namespacestd;classnumber{ Public: Number () {Data=0; } number (intvalue) {Data=value; } voidRewriteintvalue) {Data=value; } intprint () {returndata; }Private: intdata;};intMain () {cout<<"Hello Haley kong!"<<Endl; Number NUM1=Number (); cout<< Num1.print () <<Endl; Num1.rewrite (666); cout<< Num1.print () <<Endl; Number num2= Number ( -); cout<< Num2.print <<Endl; System ("Pause"); return 0;}
Fundamentals of C + + entry (1) How to write a simple class and instantiate it