Java- The meaning of >?

This means that the type parameter must support comparison with other instances of its own type, via the Comparable interface. An example of such a class is provided in the Oracle tutorial Object Ordering. Note the similar pattern to T extends Comparable<T> in the excerpt below:

g++ “because the following virtual functions are pure” with abstract base class

Your SortedContainerImpl class has two separate Container base classes. One is virtual (via the SortedContainer class) and the other is non-virtual (via the ContainerImpl class). SortedContainerImpl has concrete implementations of Container::get_size() and Container::get(int) for the base that comes in from ContainerImpl, but not for the virtual base that comes in via SortedContainer. One way to … Read more

When to use virtual destructors?

Virtual destructors are useful when you might potentially delete an instance of a derived class through a pointer to base class: Here, you’ll notice that I didn’t declare Base’s destructor to be virtual. Now, let’s have a look at the following snippet: Since Base’s destructor is not virtual and b is a Base* pointing to … Read more

Why do we need virtual functions in C++?

Here is how I understood not just what virtual functions are, but why they’re required: Let’s say you have these two classes: In your main function: So far so good, right? Animals eat generic food, cats eat rats, all without virtual. Let’s change it a little now so that eat() is called via an intermediate function (a trivial function just … Read more