Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static and Const #7

Closed
jimin-kiim opened this issue Oct 20, 2022 · 2 comments
Closed

Static and Const #7

jimin-kiim opened this issue Oct 20, 2022 · 2 comments

Comments

@jimin-kiim
Copy link
Owner

  • Static variable and function
  • Const variable and function
@jimin-kiim
Copy link
Owner Author

jimin-kiim commented Oct 20, 2022

  • normal variable : one per object

Static

Static member variable

  • all instance (objects of the class) share the same value
  • shared by all the objects that belong to the class
  • holds the value which represents the characteristic of the class, not the respective objects
  • one per class
  • cannot be initialized inside the constructor
    • because the constructor is called when the object is created.
    • should be initialized regardless of the constructor, object creation
    • should be initialized outside of the class
  • allocated only once and used for the entirety of the program.

Static member function

  • one per class
  • cannot access non static class data and functions
    • static member variables and static methods should be used regardless of the objects so it should not depend on non static data or functions

@jimin-kiim
Copy link
Owner Author

jimin-kiim commented Oct 20, 2022

Const

Const member variable

  • a variable that would not be reassigned once assigned

Const member function

  • a member function that doesn't modify any data members of the object on which it is called.(read-only function)
    • this restriction is enforced by the compiler
  • assures its clients of its benign nature. (safety, readability)
  • the keyword 'const' isn't related to the execution, it affects the safety for the programmer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant