This has got to be a simple mistake, but I've stared at it for too long now and I just don't see it. (Excuse the canned example; it's pretty close to the real thing though.)
class Foo {
public:
Foo(vector<string> things, string place) : m_thingList(things)
{
log("in Foo ctor");
validatePlacePriorToAssignment(place);
}
virtual ~Foo() {}
private:
vector<string> m_thingList;
string m_validatedPlace;
validatePlacePriorToAssignment(string p)
{
// do stuff to validate place; if not valid, throw exception
// else
m_validatedPlace = p;
}
...
};
class Bar : public Foo {
public:
const string defaultPlace = "Validville";
Bar(vector<string> stuff) : Foo(stuff, defaultPlace)
{
log("in Bar ctor");
}
...
};
someFunctionSomewhere(vector<string> allTheThings) {
try { Bar barbar(allTheThings); }
catch (...) { log("saddness"); }
}
Okay, here's the weirdness I'm seeing: there is a log entry for the Foo ctor but not the Bar ctor. I'm stack-allocating a member of a derived class; my understanding is that the base ctor is called THEN the derived ctor is called...but in this case that doesn't seem to be happening!
I'm worried that I'm doing inheritance wrong, or using initializer lists wrong, or I'm using them wrong in the context of inheritance, or for some reason it's wrong (not allowed) to validate prior to assigning in a constructor. I think I'm doing this all correctly, but obviously I'm not so here I am.
I've read through a bunch of tutorials and stackoverflow examples this afternoon, and - for the life of me - I can't figure out why this isn't working; it looks like all the sample code. If you can catch it, I'd be especially grateful.
Thank you in advance. <3