What Compile Do When An Empty Cl

2020-04-29  本文已影响0人  BeeCaffe

What Compile Do When An Empty Class Is Declared?

// the mepty class
class Empty{
};

//euqal to following
class Empty{
public:
    Empty(){};
    Empty(const Empty&){};
    Empty& operator=(const Empty&){return *this};
    inline ~Empty(){};
};

if user declares a constructor, the compile will not generate default constructor

// the mepty class
class Empty{
 public:
    Empty(int val):m_data(val){}
  private:
    int m_data;
};

//equals to following
class Empty{
public:
    Empty(int val):m_data(val){}
    //Empty(){};
    Empty(const Empty&){};
    Empty& operator=(const Empty&){return *this};
    inline ~Empty(){};
};
上一篇 下一篇

猜你喜欢

热点阅读