2021年4月25日

摘要: c++(多态) 父类的引用或者指针,指向子类对象 #include <iostream> using namespace std; class Animal{ public: //动态连遍,在父类声明函数上,变成虚函数,发生了多态 virtual void speak() { cout<<"动物在说 阅读全文
posted @ 2021-04-25 10:34 lodger47 阅读(38) 评论(0) 推荐(0)
摘要: 桶排序 例:算出随机10个数%42余数不同的有几个? #include <iostream> #include <cstring> bool a[42]; //桶 int main() { int count=0,tmp; memset(a,0,sizeof(a)); for(int i=0;i<1 阅读全文
posted @ 2021-04-25 01:00 lodger47 阅读(28) 评论(0) 推荐(0)

2021年4月24日

摘要: c++(继承 &&菱形继承) #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; class Animal { public: int m_Age; }; class Sheep :virtual publ 阅读全文
posted @ 2021-04-24 17:01 lodger47 阅读(39) 评论(0) 推荐(0)
摘要: c++(运算符重载 &&()右移运算符重载) istream& operator>>(istream& cin, MyString& str) { //先清空原有内容 if (str.pString != NULL) { delete[] str.pString; str.pString = NUL 阅读全文
posted @ 2021-04-24 11:09 lodger47 阅读(280) 评论(0) 推荐(0)
摘要: c++(运算符重载 &&()重载 //()重载 class MyPrint { public: void operator()() { cout << "hello world" << endl; } }; void test01() { MyPrint myPrint; myPrint(); // 阅读全文
posted @ 2021-04-24 10:32 lodger47 阅读(139) 评论(0) 推荐(0)

2021年4月23日

摘要: c++ (运算符重载 && []运算符重载) []运算符重载,返回数组索引的引用 int& MyArray::operator[](int index) { return this->pAddress[index]; } 阅读全文
posted @ 2021-04-23 17:53 lodger47 阅读(103) 评论(0) 推荐(0)
摘要: c++ (运算符重载 && 智能指针) class Person { public: Person(){} Person(int age):m_Age(age){} void showAge() { cout << "年龄为: " << this->m_Age; } int m_Age; ~Pers 阅读全文
posted @ 2021-04-23 17:05 lodger47 阅读(112) 评论(0) 推荐(0)
摘要: c++ (运算符重载 && ++运算符重载) class Person { public: Person(){ m_Num = 10; } //前置++ 重载 Person& operator++() { this->m_Num++; return *this; } //后置++ 重载 Person 阅读全文
posted @ 2021-04-23 16:51 lodger47 阅读(83) 评论(0) 推荐(0)
摘要: c++ (运算符重载 && 左移运算符重载) 全局函数中 ostream& operator<<(ostream &cout,Person &tmp) { cout << tmp.m_A << tmp.m_B; return cout; } 阅读全文
posted @ 2021-04-23 16:07 lodger47 阅读(65) 评论(0) 推荐(0)
摘要: c++ (运算符重载 && 基本运算符重载) #define _CRT_SECURE_NO_WARNINGS #include <iostream> using namespace std; class Person { public: Person(){} Person(int a,int b): 阅读全文
posted @ 2021-04-23 15:48 lodger47 阅读(96) 评论(0) 推荐(0)

导航