Say I have a class named Base and a class that derives from it called SuperBase. Given that add takes in a Base*, would either of these be valid:
SuperBase *super = new SuperBase;
bases.add(super);
Or
SuperBase *super = new SuperBase;
bases.add((Base*)super);
The first works as long as
SuperBasepublicly derives fromBase, via an implicit conversion from derived-to-base:The second works as well, but ignores the protection of
Base:If it’s
private, you probably shouldn’t cast to it.