Re: Getting hold of parameters in constructor
On Feb 5, 12:42am, pauldepst...@att.net wrote:
> I have a class defined as follows:
>
> class SomeClass
> {
>
> public:
>
> SomeClass( SomeType& SomeThing, AnotherType& SomeThingElse,
> YetAnotherType& YouAintSeenThis);
>
> };
>
> This constructor is the only function in the class definition. I am
> trying to write a class to handle members of SomeClass. How can I get
> hold of the parameters such as SomeThing, SomeThingElse and
> YetAnotherType without changing SomeClass?
>
> In other words, suppose x is a member of SomeClass. What is the c++
> for "the variable SomeThing (of type SomeType) that was used in the
> construction of x" ?
>
> Thank you for your .
>
> Paul Epstein
Depending on what you are trying to do with those parameters there are
a number of solutions.
It may make sense to modify the class to hold the args so you can
access
them later via functions.
Or, if there are issues with modifying the class, you can wrap the
class
with another class. The new class can save the args. Or you can even
derive from the class to accomplish a similar result.
Depends on the task at hand.
HTH
|