摘要:
```cpp#include #include #include #include struct Base { virtual void f() { std::cout init(); return ret;}void testVirtual() { //Base b; //Derived d; ////虚函数调用通过引用 ////virtual funciton call through ref... 阅读全文
posted @ 2020-02-24 19:07
i0gan
阅读(675)
评论(0)
推荐(0)
摘要:
```cpp #include #include /* 类虚函数遇到构造和析构就退化了 */ class Event; //类的前置声明 class Event {}; class Base { public: virtual ~Base() {} //why? virtual Base(int _id) : m_id(_id) {} virtual void act(Event const&) 阅读全文
posted @ 2020-02-24 19:04
i0gan
阅读(189)
评论(0)
推荐(0)
摘要:
```cpp#include #include static void versionOne();static void versionTwo();using namespace std;int main(void) { versionOne(); versionTwo(); versionThree(); return EXIT_SUCCESS;}void versionOne() { //c语... 阅读全文
posted @ 2020-02-24 19:01
i0gan
阅读(273)
评论(0)
推荐(0)
摘要:
```cpp#include #include #include #include /* 建议: 在类的构造函数中抛出异常 */class A { public: A() {}};class B : public A { public: B() {} ~B() { /*std::cout m_info; //若作为状态判断,一般声明为私有函数, 通过assert来提示. bool i... 阅读全文
posted @ 2020-02-24 18:55
i0gan
阅读(273)
评论(0)
推荐(0)
摘要:
```cpp#include /* 不要在析构函数中抛出异常 */class A { public: A() {} ~A() { std::cout << "A析构了.." << std::endl; }};/* 析构函数调用规则: 先调用成员析构 再调用派生类析构 *///析构函数绝对不要抛出异常class B : public A{ public: B() {} ~B() { std... 阅读全文
posted @ 2020-02-24 18:52
i0gan
阅读(655)
评论(0)
推荐(0)
摘要:
```cpp #include #include #include #include #include class RuleOfFive; //前置声明class class Parent; class Child { public: explicit Child(Parent *p) : m_parent(p) {} private: Parent *m_parent; }; class Par 阅读全文
posted @ 2020-02-24 18:46
i0gan
阅读(639)
评论(0)
推荐(0)

浙公网安备 33010602011771号