生活随笔
收集整理的這篇文章主要介紹了
c++ 用eclipse建立一个类,并实例化并运行
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
file->new->c/c++ project
?
?
?
?
?
//============================================================================
// Name : cpc.cpp
// Author : cpc
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "mycoach.h"
using namespace std;int main() {char hisname[]="陳培昌";mycoach a1=mycoach((char*)"程勁",22);a1.hesaid();cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!return 0;
} /** mycoach.h** Created on: 2019年8月12日* Author: root*/
#include <iostream>
#ifndef MYCOACH_H_
#define MYCOACH_H_
using namespace std;
class mycoach {
public:mycoach(char*,int);void hesaid();virtual ~mycoach();
};#endif /* MYCOACH_H_ */ /** mycoach.cpp** Created on: 2019年8月12日* Author: root*/#include "mycoach.h"
#include <iostream>
mycoach::mycoach(char *name,int age) {// TODO Auto-generated constructor stubchar *hisname=name;cout<<"大家好,我是"<<hisname<<"芳齡"<<age<<endl;
}
void mycoach::hesaid()
{cout<<"暴風雨就要來了"<<endl;
}
mycoach::~mycoach() {// TODO Auto-generated destructor stubcout<<"調用完自動銷毀了"<<endl;
} 輸出結果:
大家好,我是程勁芳齡22
暴風雨就要來了
!!!Hello World!!!
調用完自動銷毀了 ?
轉載于:https://www.cnblogs.com/saintdingspage/p/11338914.html
總結
以上是生活随笔為你收集整理的c++ 用eclipse建立一个类,并实例化并运行的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。