Compile-time polymorphism of "interfaces"
Compile-time polymorphism newbie question here. We are using virtual
functions and getting a performance hit in a device driver. Can some
suggest a way to implement this with templates? We don't actually need
run-time polymorphism, but we do want to share a bunch of code at
compile time.
class IInterface1{public: virtual void DoSomething() = 0;};
class IInterface2{public: virtual void DoSomethingElse() = 0;};
class Dervied1 : public virtual IInterface1{
int m_i;
IInterface2* m_pII2;
public:
virtual void DoSomething() {m_i++;}
void UseInterface(){m_pII2->DoSomethingElse();}
}
class Dervied1v2 : public virtual IInterface1{
int m_i;
IInterface2* m_pII2;
public:
virtual void DoSomething() {m_i++;}
void UseInterface(){m_pII2->DoSomethingElse();}
}
class Dervied2 : public virtual IInterface1{
int m_i;
IInterface1* m_pII1; //Might be a Derived1 or a Derived1v2, but it
would be nice
//to figure out at compile time and
get rid of virtual.
public:
virtual void DoSomethingElse() {m_i++;}
void UseInterface(){m_pII2->DoSomething();}
}
The ways I thought of to do this with templates all seemed to have
circular definitions.
Thanks,
Andy
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]