I did not know that abstract method cannot have implementation! |
Not quite. I had a bit biased comment there.
Pure virtual function
can have an implementation in the same class.
Pure virtual function
has to have an implementation in derived class.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
struct Foo
{
virtual void foo() = 0;
};
virtual void Foo::foo() { std::cout << 7; }
struct Bar : public Foo
{
virtual void foo() { Foo::foo(); std::cout << '\n'; }
};
void main()
{
Bar b;
Foo * p = &b;
p->foo(); // calls Bar::foo(), which uses Foo::foo()
}
|
You cannot have objects of type plain Foo, because Foo is abstract.
You can have type Bar objects, which include type Foo component.
Foo provides a default implementation for foo(), but it is up to the Bar whether it is used in any way.
So this piece of code calls tobuffer on derived class. |
Only if the real type of the object is a class derived from ECBase, ECBase introduces tobuffer() as virtual, and a derived class provides tobuffer().
if Triggger is not derived class how can they "overtype" or "retype" (idk correct term) the Trigger class to ECBase? |
They should not. If you have put a rattlesnake into an empty bag and then you put your hand into the same bag expecting to find apples, you are likely to be surprised.
However,
Trigger has nothing to do with that code. You have
t->conds
and you have told that
std::vector<Condition> conds;
. In other words, there is an attempt to use a memory location that contains a
Condition
object like it had an
ECBase
object.
You should pay much more attention to the details.