|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
pauldepstein@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" ? > There isn't one unless you save them somewhere. -- Ian Collins. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Feb 5, 12:42 am, 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 You mean you want to access the original parameter value(s) of some given type(s) that was passed into the constructor? If that/those variable(s) is/are not stored then its not stored. Given the example supplied and without modifying the original type: class Store : public SomeClass { SomeType m_some; AnotherType m_another; YetAnotherType m_yetanother; public: Store( SomeType& SomeThing, AnotherType& SomeThingElse, YetAnotherType& YouAintSeenThis) : SomeClass(SomeThing, SomeThingElse, YouAintSeenThis), m_some(SomeThing), m_another(SomeThingElse), m_yetanother(YouAintSeenThis) { } // accessors SomeType& getsome() const { return m_some; } // etc }; |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
![]() |
| Outils de la discussion | |
|
|