上一页 1 ··· 7 8 9 10 11 12 13 14 下一页
摘要: #include<iostream> using namespace std; //初识模板 //函数模板 template<typename T>//声明一个模板,告诉编译器后面代码中紧跟着的T不要报错,T是一个通用数据类型 void myswap(T *a, T *b) { T temp; te 阅读全文
posted @ 2021-01-12 21:23 loliconsk 阅读(80) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; #include<fstream> int main(void) { //1.包含头文件 fstream //2.创建流对象 ofstream ofs; //3.指定打开文件 ofs.open("text.txt", i 阅读全文
posted @ 2021-01-12 18:52 loliconsk 阅读(47) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class Base { public: //纯虚函数 //类中只要有一个纯虚函数就叫做抽象类 //抽象类无法实例化对象 //子类必须重写父类中的纯虚函数,否则也属于抽象类 virtual void func() = 0 阅读全文
posted @ 2021-01-12 18:27 loliconsk 阅读(45) 评论(0) 推荐(0)
摘要: 1.定义和初始化string对象 string s1 默认初始化,s1是一个空字符串 string s2(s1) s2是s1的副本 string s2 = s1 等价于s2(s1),s2是s1的副本 string s3("value") s3是字面值"value"的副本,除了字面值最后的那个空字符 阅读全文
posted @ 2021-01-11 17:50 loliconsk 阅读(32) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class Animal { public: //speak函数就是虚函数 //函数前面加上virtual关键字,变成虚函数,编译器在编译的时候就不能确定函数调用了 virtual void speak() { cout 阅读全文
posted @ 2021-01-11 12:37 loliconsk 阅读(50) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class person { public: person(int a, int b) { this->m_a = a; this->m_b = b; } //成员函数实现+号运算符重载 person operator+ 阅读全文
posted @ 2021-01-11 12:36 loliconsk 阅读(76) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class Building; class goodgay { public: goodgay(); public: void visit(); void visit2(); private: Building* bui 阅读全文
posted @ 2021-01-10 19:43 loliconsk 阅读(67) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class building { //告诉编译器 goodgay全局变量 是buliding的好朋友,可以访问私有内容 friend void goodgay(building* B); public: building 阅读全文
posted @ 2021-01-10 16:54 loliconsk 阅读(386) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; //静态成员函数的特点: //1.程序共享一个函数 //2.静态成员函数只能访问静态成员变量 class person { public: static void func() { b = 100; //c = 200; 阅读全文
posted @ 2021-01-10 16:16 loliconsk 阅读(75) 评论(0) 推荐(0)
摘要: #include<iostream> using namespace std; class base { public: int m_a; base() { m_a = 100; } void func() { cout << "base-调用" << endl; } void func(int a 阅读全文
posted @ 2021-01-10 13:52 loliconsk 阅读(38) 评论(0) 推荐(0)
上一页 1 ··· 7 8 9 10 11 12 13 14 下一页