随笔分类 - C++网易云课堂复习
摘要:template<class T> class shared_ptr{ public: T& operator*( ) const {return *px;} T* operator->( ) const {return px;} shared_ptr(T* p) : px(p) { } priva
阅读全文
摘要:class Fraction{ public: Fraction(int num, int den = 1) : m_numerator(num), m_denominator(den) { } Fraction operator + (const Fraction& f){ return Frac
阅读全文
摘要:转换函数 class Fraction{ public: Fraction(int num, int den = 1) : m_numerator(num), m_denominator(den) { } operator double( ) const{ //转换函数 return (double
阅读全文
摘要:Inheritance(继承),表示is-a non-virtual 函数:不希望derived class 重新定义(override,复写) virtual函数:希望derived class重新定义它(override,复写)它,并且它已经有默认定义。 pure-virtual函数(纯虚函数)
阅读全文
摘要:着一个章节主要围绕:继承,复合,委托三个方面进行介绍。 复合:表示has-a template<class T, class Sequence = deque<T>> queue<> >deque class queue{ queue中包含deque protected: deque中两端均可以进出
阅读全文
摘要:1.output函数 #include<iostream.h> ostream& operator<< (ostream& os, const String& str){ os << str.get_c_str(); return os; } { String s1("hello"); cout <
阅读全文
摘要:1.带有指针的Class,Class with pointer member 当类内带指针,一定自己写出拷贝构造函数。 String s1(); String s2("hello"); String s3(s1); 拷贝构造 s3=s2; 拷贝赋值 往往编译器会自动完成拷贝构造与拷贝赋值,不带有指针
阅读全文
摘要:1.操作符重载,(可以使用成员函数,也可以使用非成员函数) this 所有的成员函数均隐藏着一个参数,this. this与调用者相互绑定。 complex c1,c2; 对于两个复数的相加,暗含着左边加到右边。 inline complex& complex::operator += (this,
阅读全文
摘要:将构造函数放在private里面,这节视频就这样出现啦! 1.将构造函数放在private里面,表示构造函数不可以被外界调用。 complex c1(2, 1); complex c2; 上面这两个动作,不可以运行,因为构造函数放在了private里面,不允许外界私自调用。 被用到的过程(Singl
阅读全文
摘要:这节中主要讲解Class的内部声明与定义情况。 1.在类内直接定义的函数 2.在类外定义的函数 3.访问级别 4.构造函数 5.构造函数的重载(overloading) 1.complex() : re (0), im(0) {} 构造函数 2.void real(double r) {re = r
阅读全文
摘要:区分Class的分类有两大经典,1包含指针的(complex),2不包含指针的(string)。 1.complex 类分为:数据成员部分(在内存中占有数据成员的大小,数据可能会有很多份)与函数部分(只有一份)。 2.string 类中:仅包含一个指针(这里理解为这一个指针指向,数据成员),创建出的
阅读全文

浙公网安备 33010602011771号