S
Simon Elliott
I have an API which returns pointers to objects, and another API which
requires a const reference, similar to:
bloggs* find_bloggs(std::string key);
void do_stuff_with_bloggs(const bloggs& the_bloggs);
which leads to a lot of code like this:
bloggs* my_bloggs = find_bloggs("foo");
if (my_bloggs)
{
do_stuff_with_bloggs(*my_bloggs);
}
The dereference at do_stuff_with_bloggs() seems untidy and makes me
wonder if there's any overhead associated with it. Is there a neater
way of doing this, or am I stuck with it?
requires a const reference, similar to:
bloggs* find_bloggs(std::string key);
void do_stuff_with_bloggs(const bloggs& the_bloggs);
which leads to a lot of code like this:
bloggs* my_bloggs = find_bloggs("foo");
if (my_bloggs)
{
do_stuff_with_bloggs(*my_bloggs);
}
The dereference at do_stuff_with_bloggs() seems untidy and makes me
wonder if there's any overhead associated with it. Is there a neater
way of doing this, or am I stuck with it?