G
Glen Dayton
While looking at some old code I ran across a snippet that
increments a pointer to access different members of a structure:
....
struct Badness {
std::string m_begin;
std::string m_param1;
std::string m_param2;
std::string m_end;
Badness();
};
....
Badness badness;
std::string *it = &badness.m_begin;
for (++it; it != &badness.m_end; ++it) {
std::cout << it->c_str() << std::endl;
}
It just looks wrong. It depends on all of the members of class
or structure to be consistent so its bad from a maintenance
standpoint. It seems evil to use a pointer beyond the specific
object for which it is defined.
Looking wrong and evil, though, are not rational arguments that
would allow me to convince my technical lead that this code
needs to be changed sooner than later.
Anyone have good talking points?
/Glen
increments a pointer to access different members of a structure:
....
struct Badness {
std::string m_begin;
std::string m_param1;
std::string m_param2;
std::string m_end;
Badness();
};
....
Badness badness;
std::string *it = &badness.m_begin;
for (++it; it != &badness.m_end; ++it) {
std::cout << it->c_str() << std::endl;
}
It just looks wrong. It depends on all of the members of class
or structure to be consistent so its bad from a maintenance
standpoint. It seems evil to use a pointer beyond the specific
object for which it is defined.
Looking wrong and evil, though, are not rational arguments that
would allow me to convince my technical lead that this code
needs to be changed sooner than later.
Anyone have good talking points?
/Glen