vendredi 23 janvier 2015

how to inline virtual with multiple inheritance

Please do not bash me or say that I am wrong for asking this question or that multiple inheritance is evil. This question is to get a better understanding of how C++ compliers work. I know that the inline statement is used to hint the compilier to replace a function call with source code the complier has every option with or not to inline the function. If you could force inline function that would be great but that is not really the issue I am trying to solve. What I want to do is to be able to create one piece of code that is written in one place and copying and pasted in other places by the complier. The code the I write would look something like this:



struct base
{
virtual double eval() = 0; // should be no eval function for the
};

struct foo : public base
{
virtual double eval() overrides
{
return //foo eval
}
};

struct bar : public base
{
virtual double eval() overrides
{
return //foo eval
}
};

struct baz : public base
{
virtual double eval() overrides
{
return //baz eval
}
};

struct FooBarBaz : public foo, public bar, public baz
{
virtual double eval() final
{
return foo::eval() + bar::eval() + baz::eval();
}
};


the complier would generate something that is equivalent to this:



struct base
{
virtual double eval() = 0; // should be no eval function for the
};

struct foo : public base
{
virtual double eval() overrides
{
return //foo eval
}
};

struct bar : public base
{
virtual double eval() overrides
{
return //foo eval
}
};

struct baz : public base
{
virtual double eval() overrides
{
return //baz eval
}
};

struct FooBarBaz : public foo, public bar, public baz
{
virtual double eval() final
{
return /*foo eval*/ + /*bar eval*/ + /*baz eval*/
}
};


I was told that using <type_traits> is the way to solve this problem if this is true I would like to know how to get the desired results. if not I would like to know how to do this


Aucun commentaire:

Enregistrer un commentaire