C + + class-out definition

Source: Internet
Author: User

1.

#include  <iostream> #include  <string> #include <stdlib.h>using namespace  Std;class teacher{public:    void setname (string _name); string getName (); Void setgender (String _gender); Stringgetgender (); Void setage (int _age); Int getAge ( ); Void teach ();p rivate:string m_strname;string  m_gender;int m_iage;}; Void teacher::setname (string _name) { m_strname=_name;} String teacher::getname () {return m_strname;} Void teacher::setgender (String _gender) {m_gender=_gender;} Stringteacher::getgender () {return m_gender;} Void teacher::setage (int _age) {m_iage =_age;} Int teacher::getage () {return m_iage;}   void teacher::teach () {cout<< "Class   Class" &LT;&LT;ENDL;} Int main () {    teacher t;t.setname ("Confucius"), T.setgender ("male"); T.setage (;cout<) <t.getname () <<endl<<t.getgeNDEr () <<endl<<t.getage () <<endl<<endl;t.teach (); System ("pause"); return 0;} 

Operation Result:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/05/BD/wKiom1mraOPBjvDHAAAIoxF9N_o008.png "title=" Untitled. png "alt=" Wkiom1mraopbjvdhaaaioxf9n_o008.png "/>

The main thing is to declare inside the class and then define it outside of the class. Note the format at the time of definition:

The class name teacher::+ function indicates that the function is a data member in the class


C + + class-out definition

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.