vendredi 31 août 2018

C++: Parameter type that requires inheritance from few interface-like classes

I want to be able to create non-template function that requires type of class to be inherited from few another classes.

Something like that

class A1
{};

class A2
{};

class A3
{};

class B: public A1, public A2, public A3
{};

class C: public A1, public A3
{};

void Foo(const C&)
{}

int main(void)
{
    B b;
    C c;

    Foo(b); // error. But B inherited from A1 and A3, so I want to be able pass it
    Foo(c); // ok

    return 0;
}

I will glad to hear any suggestions to solve the problem.

Note: some languages like Swift and Objective-C have this functionality as part of the language calling 'conforming protocols'

Aucun commentaire:

Enregistrer un commentaire