Fundamentals of C + + entry (1) How to write a simple class and instantiate it

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.