reset password
Author Message
jpascua
Posts: 197
Posted 16:17 Jan 31, 2015 |

I'm not sure of how to implement this. Do we treat it as a class or just a file that holds non-member functions?

kknaur
Posts: 540
Posted 16:58 Jan 31, 2015 |

The Driver will have your main method.  If you have any other functions that don't belong to a specific class you have one of two ways to handle it, you can put the functions (prototypes and implementations) in the driver, or you can do separate compilation for these as well.  Create a header to have the function prototypes and another cpp file for the implementations.  Separate compilation is not just reserved for classes.

jpascua
Posts: 197
Posted 17:02 Jan 31, 2015 |

Thanks. :)

jpascua
Posts: 197
Posted 17:08 Jan 31, 2015 |

So it's fine for the implementation file to have the main function?

Last edited by jpascua at 17:09 Jan 31, 2015.
kknaur
Posts: 540
Posted 17:10 Jan 31, 2015 |

You mean the Driver.cpp have the main function? If so then yes.

jpascua
Posts: 197
Posted 17:13 Jan 31, 2015 |

Yes, but if I were to do separate compilation for Driver.cpp, can it have both the main method and the functions it implements?

kknaur
Posts: 540
Posted 17:15 Jan 31, 2015 |

Main never needs a prototype and does not have to be written with separate compilation. 

jpascua
Posts: 197
Posted 17:20 Jan 31, 2015 |

I mean to say, can I also add main() in Drive.cpp even if it's not in the Drive header?

 

kknaur
Posts: 540
Posted 17:22 Jan 31, 2015 |

Yes