If you just want to get the value, return it by value. Also declare a const function. However, if this is a large or expensive copy, it might be better to return a const link so that the caller can choose not to make a copy of it.
If you also want to change it, either return the link (or the pointer, if you want), or provide the "set" function. Alternatively, just make it public - thereβs not much point in pretending to be encapsulated when itβs not.
If you return a link (or pointer), make sure you have a const overload, otherwise you cannot read the value from const objects:
const unsigned int *Object::GetObjectIDPointer() const { return &objectID; }
source share