c++ 用eclipse建立一个类,并实例化并运行
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了c++ 用eclipse建立一个类,并实例化并运行,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1431字,纯文字阅读大概需要3分钟。
内容图文
![c++ 用eclipse建立一个类,并实例化并运行](/upload/InfoBanner/zyjiaocheng/1190/6fb1243dd2604ca3ad839f71f160e627.jpg)
- 新建项目
file->new->c/c++ project
![技术分享图片](/upload/getfiles/default/2022/10/29/20221029015442276.jpg)
- 项目结构
- cpc.cpp
//
============================================================================
//
Name : cpc.cpp
//
Author : cpc
//
Version :
//
Copyright : Your copyright notice
//
Description : Hello World in C++, Ansi-style
//
============================================================================
#include <iostream>
#include "mycoach.h"usingnamespace std;
int main() {
char hisname[]="陈培昌";
mycoach a1=mycoach((char*)"程劲",22);
a1.hesaid();
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!return0;
}
- mycoach.h
/*
* mycoach.h
*
* Created on: 2019年8月12日
* Author: root
*/
#include <iostream>
#ifndef MYCOACH_H_
#define MYCOACH_H_
usingnamespace std;
class mycoach {
public:
mycoach(char*,int);
void hesaid();
virtual ~mycoach();
};
#endif /* MYCOACH_H_ */
- mycoach.cpp
/*
* 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 stub
cout<<"调用完自动销毁了"<<endl;
}
输出结果:
大家好,我是程劲芳龄22
暴风雨就要来了
!!!Hello World!!!
调用完自动销毁了
原文:https://www.cnblogs.com/saintdingspage/p/11338914.html
内容总结
以上是互联网集市为您收集整理的c++ 用eclipse建立一个类,并实例化并运行全部内容,希望文章能够帮你解决c++ 用eclipse建立一个类,并实例化并运行所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。