Re: oo design question
Maybe my explanation was not clear enough.
Let me describe again what I want to do.
There are 4 classes, P, A, B1 and B2.
class P;
class A;
class B1;
class B2;
P "has a" A pointer.
B1 and B2 "is a" A. (i.e. B1 and B2 are the derived classes from A)
class P
{
public:
P( bool b );
void update(double t);
private:
A* _a1P;
A* _a2P;
};
Here it is assumed that (*_a1P) and (*_a2P) are the same class objects
e.g. if _a1P is the pointer of B1, then _a2P too.
P::P( bool b )
{
if( b )
{
_a1P = new B1();
_a2P = new B1();
}
else
{
_a1P = new B2();
_a2P = new B2();
}
}
void P::update(double t)
{
A& a1 = *_a1P;
A& a2 = *_a2P;
a1 += a2 * t;
}
How can you do "a1 += a2 * t" by operator overloading ?
operator+=() is easy because the returned value is not object
but reference. However, operator*() is not because it requires
copied object.
That's the reason why I posted this question here.
Do you think that this still doesn't make sense?
On Sun, 18 May 2008 10:20:51 -0400, Daniel T. wrote:
"Joseph Y. Oh" <josephyoungoh@yahoo.com> wrote:
Thanks for your answer.
Sounds like what I want is not possible...
It's not that it is not possible, it's not logical.
Let's look at the code again:
class A {
public:
virtual ~A() = 0;
};
A::~A() { }
const ? operator*( const A& left, const B& right );
Note the question mark above, what type could possibly be placed there
and have it make any sense at all?