ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ENUM Class
    카테고리 없음 2014. 4. 1. 00:26

    #include <iostream>

    #include <string>

     

    using namespace std;

    enum class mType {student, teacher, staff};

     

    class person

    {

    private :

        mType t_;

        int mId;

        string mName;

    public:

        person();// = delete; // no default constructor

        person(mType p, int id, string name) ;

        ~person();

    //    person(mType t) : t_(t) {}

    // operator mType () const {return t_;}

        auto getType() -> mType;

        void setType(mType type);

    };

     

    person::person(mType p, int id, string name) : t_(p), mId(id), mName(name)

    {

        ;

    }

     

    person::~person()

    {

        ;

    }

     

    auto person::getType() -> mType

    {

        return t_;

    }

     

    void person::setType(mType t)

    {

        t_ = t;

    }

     

    auto adding(int x, int y) -> int

    {

        return x+y;

    }

     

    void main()

    {

        cout << "main " << adding(1,2) << endl;

    //    person p1(mType::student, 1000, "Lee");

     

        person p1;

        p1.setType(mType::student);

     

        person p2(p1);

     

        person* p3 = new person;

     

        person p4[10];

     

        person* p5 = new person[10];

     

     

     

        cout << "GetType " << static_cast<int> (p1.getType()) << endl;

     

        return;

    }

Designed by Tistory.