在eclipse编写c++代码知识点小列子

2024-06-23 08:08

本文主要是介绍在eclipse编写c++代码知识点小列子,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

编写

/** Mother.cpp**  Created on: 2014-4-2*      Author: Administrator*/#include "Mother2.h"
#include <iostream>
using namespace std;
Mother2::Mother2() {}
void Mother2::print(){cout<<"this is mother2 print"<<endl;
}
Mother2::~Mother2() {}

/** Mother.h**  Created on: 2014-4-2*      Author: Administrator*/#ifndef MOTHER_H_
#define MOTHER_H_class Mother2 {
public:Mother2();virtual ~Mother2();void print();
};#endif /* MOTHER_H_ */

/** Father.cpp**  Created on: 2014-4-2*      Author: Administrator*/#include "Father.h"
#include <iostream>
using namespace std;
Father::Father() {cout<<"这是父类构造函数"<<endl;}
void Father::print(){std::cout<<"this is father print"<<std::endl;}Father::~Father() {cout<<"这是父类虚函数"<<endl;
}

/** Father.h**  Created on: 2014-4-2*      Author: Administrator*/#ifndef FATHER_H_
#define FATHER_H_class Father {
public:Father();virtual ~Father();virtual void print();
};#endif /* FATHER_H_ */

/** Mother.cpp**  Created on: 2014-4-2*      Author: Administrator*/#include "Mother.h"
#include <iostream>
using namespace std;
Mother::Mother() {cout<<"这是母类构造函数"<<endl;
}
void Mother::print(){cout<<"this is mother print"<<endl;
}
Mother::~Mother() {cout<<"这是母类虚函数"<<endl;
}

/** Mother.h**  Created on: 2014-4-2*      Author: Administrator*/#ifndef MOTHER_H_
#define MOTHER_H_class Mother {
public:Mother();virtual ~Mother();void print();
};#endif /* MOTHER_H_ */

/** Son.cpp**  Created on: 2014-4-2*      Author: Administrator*/#include "Son.h"
#include<iostream>
using namespace std;
Son::Son() {cout<<"这是子类构造函数"<<endl;}
void Son::print() {cout << "this is son demo" << endl;
}
;
Son::~Son() {cout<<"这是子类虚函数"<<endl;
}

/** Son.h**  Created on: 2014-4-2*      Author: Administrator*/#ifndef SON_H_
#define SON_H_#include "Father.h"class Son: public Father {
public:Son();virtual ~Son();void print();
};#endif /* SON_H_ */

//============================================================================
// Name        : AA.cpp
// Author      : zhubin
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<cstring>
#include"first//Mother2.h"
using namespace std;
//==运算符重载定义================================================================
// 除了类属关系运算符"."、成员指针运算符".*"、作用域运算符"::"、sizeof运算符和三目运算符"?:"以外,C++中的所有运算符都可以重载
//.运算符“=”和“&”不必用户重载//======static============================================================
//int a;//全局变量也存储在静态数据区
//int main(){
//	//int i;
//	static char str[10];
//	printf("integer: %d; string: (begin)%s(end)", a, str);
//	return 0;
//}
//========static==========================================================
//class M {
//public:
//	M(int a) {
//		A = a;
//		B += a;
//	}
//	static void f1(M m);
//private:
//	int A;
//	static int B;
//};
//
//void M::f1(M m) {
//	cout << "A=" << m.A << endl; //此句话有问题,可改为对象引用,即:m.A
//	cout << "B=" << B << endl;
//}
//
//int M::B = 0;
//void main() {
//	M P(5), Q(10);
//	M::f1(P);file: //调用时不用对象名
//	M::f1(Q);
//}
//==================================================================
//int main ()
//{
//	char *p =new char[6];char* p1= new char("hello");char* p1= new char('a');
//	//error分配一个char(1字节)的空间,
//	//用"Hello"来初始化,这明显不对
//	//p="Hello";
//	//不能将字符串直接赋值给该字符指针p,原因是:
//	//指针p指向的是字符串的第一个字符,只能用下面的strcpy(p,"hellp");cout<<p<<endl;cout<<*p<<endl;
//	int *a = new int(5);//new会在堆上分配一块内存,并会自动调用类的构造函数
//	cout<<a<<endl;
//		cout<<*a<<endl;
//		  string *str = (string*)operator new(sizeof(string));//重载new
//	delete p,a;
//	return 0;
//}
//============模板======================================================
(1)
//template<class T>
//class Base{
//
//};
//class Base1:public Base<int>{};
(2)
//template<class T>
//class Basem{
//
//};
//template<class T>
//class Basem1:public Basem<T>{
//
//};
//template<class T>
//class Test{
//private:
//	T n;
//	const T m;
//	static T x;
//public:
//	Test():n(0){}
//	Test(T t){};
//	~Test();
//	void print();
//	T operator+(T t);
//};
//template<class T>
//void Test<T>::print(){
//	cout<<"print"<<endl;
//}
//template<class T>
//int Test<T>::m=0;//初始化时候指定其类型
//template<class T>
//T Test<T>::operator +(T t){
//	return n+x;
//}
//==================================================================
//class B0 //基类B0声明
//{
//public:
//	B0(){}
//	virtual void display() {
//		cout << "B0::display()" << endl;
//	}
//	virtual ~B0(){}
//	//公有成员函数
//};
//
//class B1: public B0 //公有派生类B1声明
//{
//public:
//	//virtual B1(){}
//	virtual void display() {
//		cout << "B1::display()" << endl;
//	}
//	virtual ~B1(){}
//	//公有成员函数
//};
//class D1: public B1 //公有派生类B1声明
//{
//public:
//	//virtual D1(){}
//	void display() {
//		cout << "D1::display()" << endl;
//	}
公有成员函数
//};
//void fun(B0 *ptr) //普通函数
//		{ //参数为指向基类对象的指针
//	ptr->display(); //”对象指针—>成员名”
//}
//int main() //主函数
//{
//	B0 b0; //声明B0类对象
//	B1 b1; //声明B1类对象
//	D1 d1; //声明D1类对象
//	B0 *p; //声明B0类指针
//	p = &b0; //B0类指针指向B0类对象
//	fun(p);
//	p = &b1; //B0类指针指向B1类对象
//	fun(p);
//	p = &d1; //B0类指针指向D土类对象
//	fun(p);
//	return 0;
//}
//==================================================================
//class Father{
//	int a1,a2;
//public:
//	Father(int a,int b){a1=a,a2=b;}
//	~Father(){}
//};
//class Son:Father{
//	int a3;
//public:
//	Son(int c,int d,int e):Father(c,d),a1(c),a2(d){a3=e;}//派生类参数表
//	Son(int c,int d,int e):Father(c,d),a1(c),a2(d),a3(e){}//派生类参数表
//	Son(int c,int d,int e):a3(c){}
//};
//常对象调用常函数
//class A{//对基类成员和子对象成员的初始化必须在成员初始化列表中进行,新增成员的初始化既可以在成员初始化列表中进行,也可以在构造函数体中进行
//private:
//	int x,y;
//	mutable int a;
//	//static const int a=1;
//	//const int b=1;
//public:
//	void print();
//	void print1()const;
//	A(int x,int y,int a){this->x=x,this->y=y,this->a=a;}
//	//A(int x,int y){this->x=x,this->y=y;}
//	//A(){}
//	~A(){}
//};
//void A::print(){
//	cout<<"print===x="<<x<<",y="<<y<<endl;
//}
mutable int a=5;const int b=5;
//void A::print1()const{
//	a=44;//可以修改被定义成mutable的成员变量
//	cout<<"print1===x="<<x<<",y="<<y<<"a="<<a<<endl;int c = a+b;
//	//a=8;
//	//b=9;
//	//cout<<"a+b="<<c<<endl;
//}
//int main(){A a1(1,1);a1.print();a1.print1();const A a2(2,2);a2.print1();//常对象只能调用常成员
//	A a3(0,0,0);
//	a3.print1();
//	a3.print1();
//}
//==================================================================
//class Point {
//private:
//	int x,y;
//public:
//	Point(int a,int b){x=a,y=b;}
//	friend int len(const Point& p1,const Point& p2);
//	void changePoint(int a,int b){x+=a,y+=b;}
//	void print(void){
//		cout<<"x="<<x<<",y="<<y<<endl;
//	}
//};
//int len(const Point& p1,const Point& p2){
//	int length =(int)sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
//
//	return length;
//}
//int main(){
//	Point p1(10,10),p2(1,1);
//	p1.changePoint(100,100);
//	p1.print();
//	len(p1,p2);
//	cout<<"距离:"<<len(p1,p2);
//	return 0;
//}
//==================================================================
//windows 程序
//#include <windows.h>
//int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine,
//		int iCmdShow) {
//	MessageBox(NULL, "Hello", "Hello Demo", MB_OKCANCEL);
//	return (0);
//}//dll
//#include "dllfct.h"
//#include <stdio.h>
//#include<iostream>
//using namespace std;
//int main() {tstfunc();
//	cout<<"this is demo"<<endl;
//	return (0);
//}
//==================================================================
//c++继承
//#include <iostream>
#include"Father.h"
#include"Mother.h"
#include"first/Mother2.h"
#include"Son.h"
using namespace std;
int main() {
cout<<"this is demo"<<endl;cout << "this is eclipse demo====" << endl;
//Mother m1;//母类构造
cout<<"mmm======"<<endl;
Son s;//先构造父类再子类
Mother2 m2;
Father f1;
cout<<"+++1++++++"<<endl;
Father* f2;//不生成构造
//m1.print();
cout<<"++++2+++++"<<endl;
m2.print();
f1.print();
s.print();f2= new Son;//创建两个构造f2->print();
delete f2;
return 0;
}
//==================================================================


这篇关于在eclipse编写c++代码知识点小列子的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1086601

相关文章

关于C++中的虚拟继承的一些总结(虚拟继承,覆盖,派生,隐藏)

1.为什么要引入虚拟继承 虚拟继承是多重继承中特有的概念。虚拟基类是为解决多重继承而出现的。如:类D继承自类B1、B2,而类B1、B2都继承自类A,因此在类D中两次出现类A中的变量和函数。为了节省内存空间,可以将B1、B2对A的继承定义为虚拟继承,而A就成了虚拟基类。实现的代码如下: class A class B1:public virtual A; class B2:pu

C++对象布局及多态实现探索之内存布局(整理的很多链接)

本文通过观察对象的内存布局,跟踪函数调用的汇编代码。分析了C++对象内存的布局情况,虚函数的执行方式,以及虚继承,等等 文章链接:http://dev.yesky.com/254/2191254.shtml      论C/C++函数间动态内存的传递 (2005-07-30)   当你涉及到C/C++的核心编程的时候,你会无止境地与内存管理打交道。 文章链接:http://dev.yesky

嵌入式软件工程师应聘知识点

嵌入式软件工程师应聘 修改浏览权限 | 删除 数据结构(C语言)部分常考的知识点: 1、局部变量能、全局变量和静态变量 2、堆和栈 3、Const、volatile、define、typedef的用途 4、链表(比如链表的插入、删除和排序) 5、排序(考查冒泡法的较多) 6、可重入函数 、malloc函数 7、指针(常考函数指针,函数指针,数组指针,指针数组和

C++的模板(八):子系统

平常所见的大部分模板代码,模板所传的参数类型,到了模板里面,或实例化为对象,或嵌入模板内部结构中,或在模板内又派生了子类。不管怎样,最终他们在模板内,直接或间接,都实例化成对象了。 但这不是唯一的用法。试想一下。如果在模板内限制调用参数类型的构造函数会发生什么?参数类的对象在模板内无法构造。他们只能从模板的成员函数传入。模板不保存这些对象或者只保存他们的指针。因为构造函数被分离,这些指针在模板外

C++工程编译链接错误汇总VisualStudio

目录 一些小的知识点 make工具 可以使用windows下的事件查看器崩溃的地方 dumpbin工具查看dll是32位还是64位的 _MSC_VER .cc 和.cpp 【VC++目录中的包含目录】 vs 【C/C++常规中的附加包含目录】——头文件所在目录如何怎么添加,添加了以后搜索头文件就会到这些个路径下搜索了 include<> 和 include"" WinMain 和

uniapp接入微信小程序原生代码配置方案(优化版)

uniapp项目需要把微信小程序原生语法的功能代码嵌套过来,无需把原生代码转换为uniapp,可以配置拷贝的方式集成过来 1、拷贝代码包到src目录 2、vue.config.js中配置原生代码包直接拷贝到编译目录中 3、pages.json中配置分包目录,原生入口组件的路径 4、manifest.json中配置分包,使用原生组件 5、需要把原生代码包里的页面修改成组件的方

C/C++的编译和链接过程

目录 从源文件生成可执行文件(书中第2章) 1.Preprocessing预处理——预处理器cpp 2.Compilation编译——编译器cll ps:vs中优化选项设置 3.Assembly汇编——汇编器as ps:vs中汇编输出文件设置 4.Linking链接——链接器ld 符号 模块,库 链接过程——链接器 链接过程 1.简单链接的例子 2.链接过程 3.地址和

C++必修:模版的入门到实践

✨✨ 欢迎大家来到贝蒂大讲堂✨✨ 🎈🎈养成好习惯,先赞后看哦~🎈🎈 所属专栏:C++学习 贝蒂的主页:Betty’s blog 1. 泛型编程 首先让我们来思考一个问题,如何实现一个交换函数? void swap(int& x, int& y){int tmp = x;x = y;y = tmp;} 相信大家很快就能写出上面这段代码,但是如果要求这个交换函数支持字符型

eclipse运行springboot项目,找不到主类

解决办法尝试了很多种,下载sts压缩包行不通。最后解决办法如图: help--->Eclipse Marketplace--->Popular--->找到Spring Tools 3---->Installed。

WIN8重置Eclipse的SVN帐号密码

将C:\Users\用户名\AppData\Roaming\Subversion\auth\svn.simple目录下的文件删除,然后在Eclipse里面就需要重新输入帐号密码了。