Re: design question - member function argument or pointer member
From: Keith H Duggar (demicheme_at_aol.com)
Date: 01/26/04
- Next message: red floyd: "Re: Weird reference declaration?"
- Previous message: red floyd: "Re: what mistake I made in this head file?"
- In reply to: Gert Van den Eynde: "design question - member function argument or pointer member"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jan 2004 17:20:27 GMT
So far all of the postings have focused on inheritance, composition, etc.
However, in your original question you stated :
> object of class A needs for example for the
> operator() and object of class B
Allow me to paraphrase your statement :
A::somefunction() requires and object of class B
In that case why not follow your own suggestion of :
A::somefunction ( B const & b ) { ... }
This is what the argument list of a function are for, to supply the arguments a
function needs to carry out its work. This seems to solve all of the problems
you have outline. Namely :
1) A::somefunction is guaranteed to have an available B or it could not have
been called.
2) If other class functions require the same instance of B then simply pass
that instance to them as well :
C::somefunction ( B const & b ) { ... }
D::somefunction ( B const & b ) { ... }
etc ...
This method also has many other advantages :
1) class are not required to hold pointers or references to objects they may or
may not use. (After all, what guarantee do we have that the client will even
call somefunction.) This falls under the "only pay for what you use" paradigm
with C++ supports very well.
2) you can run A::somefunction multiple times with different B objects with a
single function call.
3) you can run A::somefunction, B::somefunction, ... , X::somefunction with
different B objects at your discretion.
In essence, this exactly what functions are designed to do: take arguments and
do work using them.
- Next message: red floyd: "Re: Weird reference declaration?"
- Previous message: red floyd: "Re: what mistake I made in this head file?"
- In reply to: Gert Van den Eynde: "design question - member function argument or pointer member"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|