d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help Needed With Some C++ Questions > Topics(contructors, Classes Etc)will Pay
Add Reply New Topic New Poll
Member
Posts: 2,081
Joined: Jan 13 2007
Gold: 515.76
Oct 25 2013 12:12pm
So i have some questions if anyone could help me answer them that would be greatly appreciated. and fg will be given as well.

pm/post if you can help.
ex. what would the constructor be for the class Derived
Code
class Derived : public Base
{
private:
const int ID;
static int count;
public:
// insert your code

};
int Derived::count = 1;

with many more questions
lmk, thanks :)
Member
Posts: 1,358
Joined: Dec 30 2012
Gold: 0.10
Oct 25 2013 01:02pm
It depends on what your classes do but in this case it would probably be

Code
Derived(const int id) : ID( id ) { };


This should help: http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/

This post was edited by SelfTaught on Oct 25 2013 01:06pm
Member
Posts: 2,081
Joined: Jan 13 2007
Gold: 515.76
Oct 25 2013 01:09pm
Quote (SelfTaught @ Oct 25 2013 07:02pm)
It depends on what your classes do but in this case it would probably be

Code
Derived(const int id) : ID( id ) { };


This should help: http://www.learncpp.com/cpp-tutorial/114-constructors-and-initialization-of-derived-classes/


Thanks, I know of that site, that was just an example, pmed with the whole problem
Member
Posts: 2,081
Joined: Jan 13 2007
Gold: 515.76
Oct 25 2013 04:19pm
When will this invoke the base class implementation of doit()?
Code
Derived d;
Base *bp = &d;
bp->doit();

Member
Posts: 237
Joined: Aug 6 2011
Gold: 6,026.00
Oct 28 2013 06:11pm
This will always invoke the base class member. If there is no such member in the base class, you'll get a compile error.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll