Class variables: public access read-only, but private access read/write

后端 未结 12 716
感动是毒
感动是毒 2020-11-28 05:25

Whoopee, not working on that socket library for the moment. I\'m trying to educate myself a little more in C++.

With classes, is there a way to make a variable read-

12条回答
  •  生来不讨喜
    2020-11-28 06:32

    but temp.x = 5; not allowed?

    This is any how not allowed in the snippet posted because it is anyhow declared as private and can be accessed in the class scope only.

    Here are asking for accessing

    cout << temp.x << endl;

    but here not for-

    int myint = temp.x;

    This sounds very contradictory.

提交回复
热议问题