D
drmario
Last night I was reading a tutorial on writing C++ classes called "The ABCs
of Writing C++ Classes" at http://www.acm.org/crossroads/xrds1-4/ovp.html
About halfway down, in Guideline 8, he says:
Suppose we decided to derive a class Triangle from Shape:
class Triangle : public Shape {
public:
Triangle (const Point center,
const int color,
const Point v1,
const Point v2,
const Point v3);
private:
Point _v1, _v2, _v3;
};
I don't understand why these parameters are specified as value parameters.
Why would you want to pass in four Point values, and an integer, by value?
Now you will have extra memory taken up for the integer, as well as four
calls to Point's constructor AND extra memory for the instances of those
objects. Why not simply use reference parameters? Could someone explain to
me why you would EVER pass by value as opposed to const reference?
Thanks
Mario
of Writing C++ Classes" at http://www.acm.org/crossroads/xrds1-4/ovp.html
About halfway down, in Guideline 8, he says:
Suppose we decided to derive a class Triangle from Shape:
class Triangle : public Shape {
public:
Triangle (const Point center,
const int color,
const Point v1,
const Point v2,
const Point v3);
private:
Point _v1, _v2, _v3;
};
I don't understand why these parameters are specified as value parameters.
Why would you want to pass in four Point values, and an integer, by value?
Now you will have extra memory taken up for the integer, as well as four
calls to Point's constructor AND extra memory for the instances of those
objects. Why not simply use reference parameters? Could someone explain to
me why you would EVER pass by value as opposed to const reference?
Thanks
Mario