zoukankan      html  css  js  c++  java
  • Effective C++条款05:了解C++默默编写并调用哪些函数

    class Empty{};
    
    class Empty{
        Empty(){};
        Empty(const Empty& rhs){};
        ~Empty(){};
        Empty& operator=(const Empty& rhs){};
    
    };
    

    只有当生成的代码合法证明它有意义时编译器才会为class生成operator=

    template<class T>
    class NameObject{
        private:
        string& nameValue;
        const T objectValue;
    };
    

    如上,对于引用和const,编译器拒绝赋值
    还有一种情况:某个基类将拷贝赋值函数声明为private,则编译器拒绝为派生类生成拷贝赋值函数,毕竟编译器所生成的拷贝赋值函数想象可以处理基类部分,所以无法在派生类调用基类的拷贝赋值函数

    请记住

    编译器默认为class生成默认构造函数,拷贝构造函数,拷贝赋值函数,析构函数

  • 相关阅读:
    C#操作Redis Set 无序集合
    C#操作Redis Hash数据表
    C#操作Redis List 列表
    C#操作Redis String字符串
    Redis 小结
    建造者模式
    外观模式
    模板方法模式
    原型模式
    select ie6 的bug 层级
  • 原文地址:https://www.cnblogs.com/qbits/p/11055688.html
Copyright © 2011-2022 走看看