On Sep 5, 11:24 am, Anton Bredikhin <duud...@gmail. comwrote:
Hello!
I have a class hierarchy that consists mainly of one base class
CtxBase, and two children: LoginCtx and DisconnectCtx.
Now, there's a need to provide an interfaces for this hierarchy. I'd
like to export this classes from a DLL.
And I'm in doubt how can I achieve this?
My first option was to define a base interface (ICtxBase) and then
derive both ILoginCtx and IDisconnectCtx from it. But using this
approach I get ambiguous calls inside derived classes, cause the
inherit from both their specific interfaces and the base classs,
making the base interface ICtxBase to appear in the hierarchy twice.
Why would you inherit from an interface to blueprint your derived
classes?
Ask yourself if DisconnectCtx is_a interface?
Sshow a simple reconstruction of the problem you have.
How difficult could that be?
#include <iostream>
class ICtx
{
public:
virtual void foo() const { std::cout << "ICtx::foo()\n" ; }
};
class ILoginCtx : public ICtx { };
class Ctx
{
public:
virtual void login(const ILoginCtx& ri) = 0;
};
void Ctx::login(cons t ILoginCtx& ri)
{
std::cout << "Ctx::login()\n ";
ri.foo();
}
class LoginCtx : public Ctx
{
public:
virtual void login(const ILoginCtx& ri)
{
std::cout << "LoginCtx::logi n()\n";
Ctx::login(ri);
}
};
int main()
{
LoginCtx ctx;
ILoginCtx interface;
ctx.login( interface );
}
>
Can anyone tell me, is there a standard approach for such situation?
Thanks!
First thought that comes to mind is that you have a potential design
issue. One class appears to be responsible for Logins and another for
Disconnects? Wouldn't it make more sense that a SessionCtx class and
its derivatives handle both connects and disconnects, perhaps each
derivative does that in a different way?