← Back to team overview

kicad-developers team mailing list archive

Re: [PATCH 0/4] Use of "virtual" and "override" keywords

 

Hi Wayne,

On 12.07.2016 16:07, Wayne Stambaugh wrote:

> I was looking over this patch set and before I apply it I want to be
> sure that all base class functions declared as virtual are explicitly
> declared as override in the derived classes.  It's a very large patch
> set and I don't have time to confirm that this is the intent of these
> patches.

The patches will need to be rebased anyway, there have been several changes.

The first patch enables a warning for all functions that override
virtual functions in base classes but have no "override" -- that is how
I identified the implicitly virtual functions.

Whether we also add a "virtual" in addition to the "override" is a
question of code legibility, personally I find it more obvious to be
explicit here. It might also be an idea to place these in a separate
block inside the class definition, e.g.:

struct A {
	virtual void a() = 0;
};

struct B : A {
	virtual void b() = 0;
};

struct C : B {
	// A
	virtual void a() override;

	// B
	virtual void b() override;
};

This is what I do in my projects, and I've found it to be a tremendous
help, as it tells me that this function is likely to be called by code
that doesn't know the concrete type, but only the base class mentioned
in the comment above.

   Simon

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups

References