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.
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.
const ABC *object = new ABC();
const_cast<ABC*>(object)-> rucrazy();
_novi_
const_cast<ABC*>(object)->
_novi_
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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?