|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (8 bit)
|
Stubs and Drivers?
Hello,
As I have mentioned in other threads, I am right in the middle of a class on C++. We just covered a short section on stubs and drivers. I am unclear as to how these are written, how they are used and why. Maybe someone can put this concept into a different perspective. As my boss said when I said I had a stupid question for him, "there is no such thing as a stupid question, just stupid people"...I hope this does not apply here ;-) |
|
|
|
|
|
#2 |
|
Member (7 bit)
Join Date: Sep 2002
Posts: 93
|
Hey, we all knew squat at one point.
A stub is basically a place holder for a function or method that you know you will need. It's part reminder, part making the compiler happy in some cases. For example, you know you are going to need an insert method, so remind yourself by throwing a stub into your .h file and throw a declaration in the source code. For example... class Person { public: Person( ) //defined in source code ~Person( ) //defined in source code void insert( int x ); private: string name; int age; int weight; } And in the source code you'd have the function... void insert( int x ) { **insert's code** } So you see, it's nothing more than a placeholder, sometimes neccesary to make the skeleton of the program. Ok, as for a driver, it is basically the implementation of other classes and it's methods. I know that doesn't sound concrete, but let me try to make an example. Say I wrote my Person class, and I wrote all the source codes for the methods in the Person class. By itself, that code doesn't do a whole lot. It just sits there looking pretty waiting to be used. That's where the driver comes in. It actually implements that source code towards something useful. All you need to do is #include "person.h", assuming that's what we called the above .h file. I hope that helps, please don't be afraid to ask if some things aren't clear!
|
|
|
|
|
|
#3 |
|
Member (8 bit)
|
Thanks!! That does help. That is exactly what the stubs and drivers do in the program we are doing for a project. Right now they don't do much but they "hold the place" for when they are needed in chapters to come.
I am sure I will be back here with more questions. Next week is the final for this term and the following week we begin a new term. It will pick up where we left off. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|