- 博客(14)
- 收藏
- 关注
原创 C++STL中deque容器的相关知识
deque是“double-ended queue”的缩写,和vector一样都是STL的容器,deque是双端数组,而vector是单端的。deque在接口上和vector非常相似,在许多操作的地方可以直接替换。deque可以随机存取元素(支持索引值直接存取, 用[]操作符或at()方法,这个等下会详讲)。deque头部和尾部添加或移除元素都非常快速。但是在中部安插元素或移除元素比较费时...
2018-08-08 10:15:41
207
原创 C++STL中vector容器的相关操作
一:无参构造理论知识vector采用模板类实现,vector对象的默认构造形式vector<T> vecT; vector<int> vecInt; //一个存放int的vector容器。vector<float> vecFloat; //一个存放float的vector容器。vector<string...
2018-08-06 17:43:32
250
原创 C++STL中string容器的相关知识
一:string的构造函数默认构造函数: string(); //构造一个空的字符串string s1。拷贝构造函数: string(const string &str); //构造一个与str一样的string。如string s1(s2)。带参数的构造函数 string(const cha...
2018-08-06 17:27:07
185
原创 类模板的运用
#include<iostream>using namespace std;class MyArray{private: int m_len; int *m_data;public: int &operator [](int index) { return m_data[index]; } int GetLength() { return m...
2018-08-04 18:30:33
299
原创 C++多态相关知识
1:每一个类都有虚表 2:虚表可以继承,如果子类没有重写虚函数,那么子类虚表中仍然会有该函数的地址,只不过这个地址指向的是基类的虚函数实现,如果基类有3个虚函数,那么基类的虚表中就有三项(虚函数地址),派生类也会虚表,至少有三项,如果重写了相应的虚函数,那么虚表中的地址就会改变,指向自身的虚函数实现,如果派生类有自己的虚函数,那么虚表中就会添加该项。 3:派生类的虚表中虚...
2018-08-02 15:37:04
226
原创 C++公司员工的简单功能实现
Employee.h#ifndef _EMPLOYEE_H#define _EMPLOYEE_H#include <iostream>#include <string>using namespace std;class Employee{protected: static int num; int m_id; string m_name; ...
2018-08-02 10:38:47
1308
原创 C++类模板中的static
#include<iostream>using namespace std;template <typename T>class A{private: int m_a;public: static T count; A() { count++; }};template <typename T&...
2018-08-02 10:21:35
473
转载 有关const *和* const
1、const *:表示指针指向的值不可变,但是指针可以重新赋新地址 #include <stdlib.h> #include <stdio.h> #include <string.h> int main(void) { int test1 = 1; int test2 = 2;...
2018-08-02 10:00:29
533
原创 c++的简单排序
/*对一个5位数的任意整数,求出其降序数。例如,整数是82319,则其降序数是98321。算法提示:将整数的各位数分解到一维整型数组a中,再将a数组中的元素按降序排序,最后输出a数组元素值。试建立一个类DescendNUM,用于完成该功能。*/#include<iostream>using namespace std;class DescendNUM{private: ...
2018-07-29 11:10:09
962
原创 c++继承的简单问题,circle,rectangle继承shape
#define PI 3.14#include<iostream>using namespace std;/*建立一个形状类Shape作为基类,派生出圆类Circle和矩形类Rectangle,求出面积并获取相关信息。具体要求如下:(1)形状类Shape(a)保护数据成员double x,y:对于不同的形状,x和y表示不同的含义,如对于圆,x和y均表示圆的半径,而对于矩形...
2018-07-29 10:04:10
2294
原创 c++关键字static在类中的相关操作
#include<iostream>using namespace std;class A{public: static int count;//类中声明 A() { count ++; } int get_count() { return count; }}; int A::cou...
2018-07-28 21:25:01
109
原创 c++中友元类的使用
#include<iostream>using namespace std;class A{ friend class B;private: int m_a;public: A(int a) { m_a=a; }};class B{private: int m_b;public: B(int b...
2018-07-27 16:44:21
1249
原创 c++运算符重载与string一些函数的实现
1.。。h文件#ifndef _MYSTRING_H#define _MYSTRING_H#include<iostream>using namespace std;class MyString{ friend ostream &operator<<(ostream &out,const MyString &m); f...
2018-07-26 21:02:09
145
原创 C++中static的相关用法
1。。静态成员变量#include <iostream>#include <string.h>using namespace std;class Student {private: char name[20];public: static int count; //静态成员变量在类里面声明 所有对象共享静态成员变量public: ...
2018-07-25 13:27:26
146
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人