N
number774
I've used Boost for this example; in fact we have our own pointer
class, for historic reasons.
#include "boost\shared_ptr.hpp"
// A heirarchy of classes
class G1 {};
class G2: public G1 {};
// A method which takes a shared pointer to the base class
void f(boost::shared_ptr<G1>) {};
// A method which takes a shared pointer to some other class
void f(boost::shared_ptr<int>) {};
void main()
{
// Call a method with a shared pointer to a derived class
f(boost::shared_ptr<G2>());
}
This fails, because the compiler is unable to decide which of the two
methods is meant. Of course, to a human, it's pretty obvious which
one is meant, but there doesn't seem to be enough information at the
time for the compiler to decide. In practice I have several hundred
functions, and 50 or so classes, to get confused among, so I don't
really want to take the obvious route [declare an
f(boost::shared_ptr<G2>) ]. Is there anything I can do to the pointer
class, or even to the class inheritance, that'll help the compiler
out?
Thx
class, for historic reasons.
#include "boost\shared_ptr.hpp"
// A heirarchy of classes
class G1 {};
class G2: public G1 {};
// A method which takes a shared pointer to the base class
void f(boost::shared_ptr<G1>) {};
// A method which takes a shared pointer to some other class
void f(boost::shared_ptr<int>) {};
void main()
{
// Call a method with a shared pointer to a derived class
f(boost::shared_ptr<G2>());
}
This fails, because the compiler is unable to decide which of the two
methods is meant. Of course, to a human, it's pretty obvious which
one is meant, but there doesn't seem to be enough information at the
time for the compiler to decide. In practice I have several hundred
functions, and 50 or so classes, to get confused among, so I don't
really want to take the obvious route [declare an
f(boost::shared_ptr<G2>) ]. Is there anything I can do to the pointer
class, or even to the class inheritance, that'll help the compiler
out?
Thx