answersLogoWhite

0


Best Answer

You would place the const keyword before the function body:

class Object

{

public:

Object():m_num(1){}

int GetData() const;

private:

int m_num;

};

int Object::GetData() const {

return(m_num); }

Since GetData() does not alter the instance, it makes sense to declare the function as constant.

Note that class instance data members that are declared mutable can still be altered, regardless of constant functions. The use of constant functions only guarantees the non-mutable members cannot be altered.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If you want to guarantee that the object remains the same after calling a member function on it how would you declare the function?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you replace a formula with its function so it remains constant?

No but if you replace a constant with a function it will remain a formula


Is it true that the lighter something is that it has less density?

No. Volume must be carefully considered as well before you can, with certainty, so declare. If, however, the volume either remains the same or increases, whicle the mass is reduced, then, and only then, can you declare density has decreased.


How long is Puerto Rico known as a country?

It began calling itself a Commonwealth in 1952, but under International Law it remains an unincorporated US Territory


When calling from a bt landline what number do you dial in order that your number remains private?

To withhold your number - dial 141, followed by the number you want to call


What do daughter cells do once they are formed?

They function as a normal nucleus. It remains like that until next division begins.


Who were the people who first used fire to cook food?

cavemen? A2. The earliest is lost in the mists of time. From midden and fire remains, we can give an educated guess, but these have no guarantee of being the earliest.


A type of homologous structure that remains in an organism through evolution but no longer serves any biological function?

Vestigial structure


What is the rothalpy?

It is a function/property that remains constant throughout a rotating machine,i.e in an adiabatic irreversible process relative to the rotating component.


How does cutin on an apple suit its function?

The cutin on the apple suits its function because it induces water conservation and also acts as an infectional prevention. Thus, the apple remains intact in terms of moist and taste.


Is there another alternative to the D and C?

If you have remains left inside the doctor can give you the option of the second medication used in abortion, which is Misoprostol. it will induce cramps but there is no guarantee it will work. A D&C is sure to work.


What function does the nictitating membrane have in the pig?

In mammals (such as your pig) it is vestigial- meaning it most likely has no function but remains because its ancestors used it. It is a remnant of earlier evolution when this eyelid used to be used to help moisten and protect the eyeball.


What if the rate of change is a measure of how fast the function is increasing or decreasing what does the slope of a linear?

The slope of a linear function is also a measure of how fast the function is increasing or decreasing. The only difference is that the slope of a straight line remains the same throughout the domain of the line.