How to write a simple class in C++?

后端 未结 4 582
夕颜
夕颜 2020-12-13 13:42

I have been reading a lot of tutorials on C++ class but they miss something that other tutorials include.

Can someone please show me how to write and use a very simp

4条回答
  •  借酒劲吻你
    2020-12-13 13:50

    class A
    {
      public:
        // a simple constructor, anyone can see this
        A() {}
      protected:
        // a simple destructor. This class can only be deleted by objects that are derived from this class
        // probably also you will be unable to allocate an instance of this on the stack
        // the destructor is virtual, so this class is OK to be used as a base class
        virtual ~A() {}
      private:
        // a function that cannot be seen by anything outside this class
        void foo() {}
    };
    

提交回复
热议问题