vendredi 27 mars 2015

Base class with pure virtual functions

I have a class layout similar to this:



class O {};

class D : public virtual O {
public:
virtual float foo() const = 0;
};

class B : public D {
public:
B(float, float) {}
};

class R : public B {
public:
R() : B{1.f, 1.f} {}
virtual float foo() const override { return 0.f; }
};

int main() {
R r;
}


It compiles fine with clang 3.6 but it fails to compile with gcc 4.9, because it cannot allocate an object of abstract type. How can I fix this in gcc?


EDIT

Here it compiles, while here it does not. The only difference is that in the second case the constructor of my base class takes two floats instead of one.

Any ideas?


EDIT2

It also compiles when using normal braces instead of curly braces to initialize B, so I guess it has something to do with that?


EDIT

I edited the code, which instantiates an object R. It still compiles on Clang 3.6 but still fails on GCC 4.9.2.


Aucun commentaire:

Enregistrer un commentaire