Object-oriented for C + +

Source: Internet
Author: User

Here is a header file people.h, this header file has a class people, the class has an implementation of the method SayHello ();

1 class people{23public:4     void SayHello (); 5 };

Next, the source file implements the people SayHello method for printing a sentence;

#include <iostream>"people.h"usingnamespace  std; void People::sayhello () {    cout<<"Hello world! "<<Endl;}

Finally, the main function of the file, the main new people object, and called his SayHello object to print a word; 1 #include <iostream>

1#include <iostream>2#include"people.h"3 using namespacestd;4 5 //class people{6 //7 //Public :8 //void SayHello () {9 //cout<< "Hello world!" <<endl;Ten //    } One //}; A  - intMain () { -People *p =Newpeople (); the     //call the SayHello method of the object -P->SayHello (); -  -     /*Delete objects that are not used*/ + delete p; -     return 0; +}

In fact, the object-oriented mechanism of C + + and other object-oriented programming languages, the logic is the same, but there may be some grammatical differences, that's all.

Object-oriented for C + +

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.