What member functions you need for a car class (or a dog class) depends entirely on what you actually need to do with the class.
In general, you obviously need to do the same work whether it is in an object oriented programming language (such as C++) or a procedural language like C.
The difference is that you do the work WITH a class member, rather than as a function that takes an explicit parameter of some sort.
So, for example, if we want to draw a rectangle in C:
Code:
void drawRectangle(int x, int y, int w, int h)
{
line(x, y, x+w, y); // Top horizontal line.
line(x+w, y, x+w, y+h); // Right side vertical line.
line(x+w, y+h, x, y+h); // Bottom horizontal line
line(x, y+h, x, y); // Left side vertical line
}
int main()
{
drawRectangle(100, 100, 300, 200);
}
In C++, the same thing could, perhaps be done by having a rectangle class:
Code:
class rectangle
{
int x, y, w, h;
public:
rectangle(int ax, int ay, int aw, int ah) : x(ax), y(ay), w(aw), h(aw) {};
void draw();
}
void rectangle::draw()
{
line(x, y, x+w, y); // Top horizontal line.
line(x+w, y, x+w, y+h); // Right side vertical line.
line(x+w, y+h, x, y+h); // Bottom horizontal line
line(x, y+h, x, y); // Left side vertical line
}
int main()
{
rectangle r(100, 100, 300, 200);
r.draw();
}
So as you can see, in the object oriented world, we first construct a rectangle, then draw it, whereas in the C world, we call a function that knows how to draw a rectangle - both drawing functions do the exact same thing, but one uses the implicit knowledge of the rectangle size given in the constructor, the other the values given by the calling code.
It's probably not a very good example, but...
--
Mats