詳細說明C++代碼編輯問題
作者:佚名
許多編程人員學習C++代碼總結(jié)經(jīng)驗為,有的覺得C++語言是一門獨立的語言,并不是在C語言的基礎(chǔ)上,可以直接學習C++不必先從C下手。
下面著重講述學習C++時碰到的相關(guān)難題和問題,以及學習C++的技巧,如何更好的進行C++的學習,開始學習了一下C++代碼知識,發(fā)現(xiàn)自己還是又很多遺漏的角落。下面是一個基礎(chǔ)示例:
- #include "stdafx.h"
- #include "iostream.h"
- class student//基類
- {
- private:
- int stu_num;
- char* stuname;
- char* sex;
- protected:
- public:
- student(){};
- student(int num,char* name,char* sex);
- student* get();
- void virtual printstu();//虛函數(shù)聲明,一旦基類聲明虛函數(shù),派生類就一定是虛函數(shù)即便不寫virtual
- void setname(char* name);
- void friend setsex(student* stu,char* sex);
- student operator++(int);//運算符重載
- };
- student student::operator ++(int)
- {
- student s;
- s.stu_num=stu_num++;
- return s;
- }
- void setsex(student* stu,char* sex)//友元函數(shù)
- {
- stu->sexsex=sex;
- }
- inline void student::setname(char* name)//內(nèi)聯(lián)函數(shù)
- {
- this->stuname=name;
- }
相信大家看了以上的C++代碼,剖有感受,希望大家能夠?qū)W到知識,本站還會不斷更新。
【編輯推薦】
責任編輯:chenqingxiang
來源:
機械工業(yè)出版社