Skip to content

Abstract types cannot have optional references #19

Description

@hostilefork

I noticed this when trying out the optional references:

#include "Optional/optional.hpp"

using std::experimental::optional;

class foo {
    virtual void doSomething() = 0;
};

class bar : public foo {
    void doSomething() override {
    }
};

int main() {

    // This works...

    int i = 3;
    int & ir = i;
    optional<int &> oir = ir;

    // And so does this...

    bar b;
    foo & fr = b;
    bar & br = b;
    optional<bar &> obr = br;

    // But this does not...

    optional<foo &> ofr = fr;
}

The error that comes up is:

cannot allocate an object of abstract type ‘foo’ because the following virtual functions are pure within ‘foo’: virtual void foo::doSomething()

One is able to have raw references to an abstract type. So it would seem that an optional reference could be had to an abstract type as well?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions