class Base
{
protected:
virtual ~Base() {}
virtual void MethodThatDoesAThing() = 0;
};
class Derived : public Base
{
public:
virtual void MethodThatDoesAThing() override;
};
void Callee(Base* base)
{
base->MethodThatDoesAThing();
}
void Caller()
{
static Derived derived;
Callee(&derived);
}
Surprisingly, VS 2015 compiles this without complaint. I would have expected this to be a compiler error.
When you realize how dumb a bug is...
[edit] Wait... How does Callee not generate an error when it calls a protected function??
[edit2] how are you passing a Derived& to a function that takes a Base*? :P
C++ allows overriding your parent's privates.
With public methods? That seems smelly. In that case, maybe this post should be in the "why didn't somebody tell me" thread.
[edit] Wait... How does Callee not generate an error when it calls a protected function??
In the actual code, Callee is a method on a friend class of Base (but not Derived). Thought it would be simpler to omit that. This isn't code I'd expect anyone to run through a compiler. ;)
[edit2] how are you passing a Derived& to a function that takes a Base*? :P
Whoops. Fixed.
Anyway, upon further reflection, this may not have even been the problem. That would be in line with what I get for jumping to conclusions after only 15 minutes.
C++ allows overriding your parent's privates.
I'm having a hard time reading this with a straight face.
I've run into similar problems with some programming projects for school.
i had one project where I had to build a basic ATM and couldn't figure out why the balance for the second person was showing the first person's balance and why the withdraw amount was adding to the balance. I swear it took me longer than it should have to realize that when I duplicated the code for my deposit function and for the second customer I forgot to go in and change the computation signs even though I changed the variable from deposit to withdraw and forgot to change my customer variable form customer1 to customer2. I felt so dumb when I realized it.
This is why I put indenting and // before the quotes and not inside them. (surprised the link stage didn't complain though? is that OK?)
I was fighting a bug in the last couple dev sessions I did where my UI would not rasterize my variable, for showing the player, from floats to ints even though I had placed a (int) cast.
the line looked like this (approx.):
hpTextField.text = (int)curHP * modifier + "/" + (int)maxHP * modifier;
With modifier being a float, can you see my error? I didn't... for a week. (working on it on and off)
Spoiler, it was supposed to be (int)(curHP * modifier)