G
Gianni Mariani
In the code below, controller::controller() is never invoked, however,
it appears there is no way to make a compile-time rule that this should
not happen. The code below seems to make compilers complain that
controller::controller() is private, even though it is never used.
What do others do to work-around this ? I suppose I can simply
not implement controller::controller(), that way I get a linking
error if there exists errant code. (ok tried that - gcc seems to
detect errors and all is fine, MSVC seems to need the constructor
even though it should never be invoked.)
Especially when a class has no way of being constructed alone (due to
pure virtual methods), there should be not reason to access default
virtual constructors since they can never be called hence there should
be no violation of the access rule.
class controller
{
controller(); // private don't want anyone to call this
public:
controller( int ); // this should be called instead
};
class Interface
: virtual public controller
{
public:
virtual void DoThing() = 0;
};
class Interface_Impl1
: public Interface
{
public:
virtual void DoThing1() = 0;
virtual void DoThing()
{
DoThing1();
}
};
class Interface_Impl2
: public Interface
{
public:
virtual void DoThing2() = 0;
virtual void DoThing()
{
DoThing2();
}
};
class Interface_Impl3
: public Interface
{
public:
virtual void DoThing()
{
// doing 3
}
};
class Application
: public Interface_Impl1,
public Interface_Impl2
{
Application()
: controller( 3 )
{
}
void DoThing1()
{
// Doing 1 it here !
}
void DoThing2()
{
// Doing 2 it here !
}
};
it appears there is no way to make a compile-time rule that this should
not happen. The code below seems to make compilers complain that
controller::controller() is private, even though it is never used.
What do others do to work-around this ? I suppose I can simply
not implement controller::controller(), that way I get a linking
error if there exists errant code. (ok tried that - gcc seems to
detect errors and all is fine, MSVC seems to need the constructor
even though it should never be invoked.)
Especially when a class has no way of being constructed alone (due to
pure virtual methods), there should be not reason to access default
virtual constructors since they can never be called hence there should
be no violation of the access rule.
class controller
{
controller(); // private don't want anyone to call this
public:
controller( int ); // this should be called instead
};
class Interface
: virtual public controller
{
public:
virtual void DoThing() = 0;
};
class Interface_Impl1
: public Interface
{
public:
virtual void DoThing1() = 0;
virtual void DoThing()
{
DoThing1();
}
};
class Interface_Impl2
: public Interface
{
public:
virtual void DoThing2() = 0;
virtual void DoThing()
{
DoThing2();
}
};
class Interface_Impl3
: public Interface
{
public:
virtual void DoThing()
{
// doing 3
}
};
class Application
: public Interface_Impl1,
public Interface_Impl2
{
Application()
: controller( 3 )
{
}
void DoThing1()
{
// Doing 1 it here !
}
void DoThing2()
{
// Doing 2 it here !
}
};