
面对对象
解除
世界很精彩!
展开
-
033:排序,又见排序---函数模板
#include <iostream>using namespace std;bool Greater2(int n1,int n2) { return n1 > n2;}bool Greater1(int n1,int n2) { return n1 < n2;}bool Greater3(double d1,double d2){ return d1 < d2;}template <class T1,class T2>void原创 2022-04-07 22:33:29 · 715 阅读 · 1 评论 -
019:全面的MyString
#include <cstdlib>#include <iostream>using namespace std;int strlen(const char * s) { int i = 0; for(; s[i]; ++i); return i;}void strcpy(char * d,const char * s){ int i = 0; for( i = 0; s[i]; ++i) d[i] = s[i]; d[i] = 0; }int s原创 2022-04-06 14:12:13 · 281 阅读 · 0 评论 -
018:别叫,这个大整数已经很简化了
#include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> using namespace std;const int MAX = 110; class CHugeInt { private: char buf[220]; void reverse() { int tmp; int len = strlen(buf); for原创 2022-04-05 14:20:45 · 473 阅读 · 0 评论 -
014:MyString
1、右边赋值字符串类型要进行重载,右边赋值是同类时要深拷贝。2、同时,复制构造函数需要重载,深拷贝。3、友元函数可以在类里面定义,是全局函数。(赋值重载时,忘记写返回值return (*this),本地是对的,但是提交会报错,不知道啥原因)参考:014 MyString#include <iostream>#include <string>#include <cstring>using namespace std;class MyString { ch原创 2022-04-04 18:19:48 · 939 阅读 · 2 评论 -
013:魔兽世界之一:备战
这里有两个类,武士类和阵营类,建议从main函数开始阅读。#include <iostream>#include <cstring>using namespace std;const int WARRIOR_NUM = 5;class Cheadquarter;class CWarrior{private: Cheadquarter * pheadquarter;//武士所属阵营的指针 int kindNo;//武士编号的种类 0 dragon 1 ...原创 2022-04-04 09:54:21 · 606 阅读 · 0 评论