Link to home
Start Free TrialLog in
Avatar of jastiwana
jastiwana

asked on

Accessing inline function of a class through const pointer object.

Hi all
i hav a class say ABC. ABC has an inline func
inline bool ABC::rucrazy()
{
return m.crazy;
}

Now i want to access this inline fucntion.
If i have ABC &object, then object.rucrazy() works.
but if i have const ABC *object, then i m unable to get the
value of crazy.
It say "Cannot convert from const ABC to ABC &".
is there any way out?
(its kinda urgent.so pz try 2 b quick :)))

Thanks
Jastej.
Avatar of furqanchandio
furqanchandio

hi

the problem i see is that the pointer ABC* object needs to be assigned an address of an object or allocated using new.
if u have try using object->runcrazy(); ( object is a pointer afterall)


OR

maybe ur runcrazy function is modifying data therefore it cant be assigned const


kindly show the code of the runcrazy function. is this the complete code of runcrazy?
const ABC *object = new ABC();
const_cast<ABC*>(object)->rucrazy();

_novi_
ASKER CERTIFIED SOLUTION
Avatar of novitiate
novitiate

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

inline bool ABC::rucrazy()
{
return m.crazy;
}

should be
 
inline bool ABC::rucrazy() const
{
return m.crazy;
}

but since you don't explain what m is there might be further problems with that.