Getting hold of parameters in constructor

P

pauldepstein

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 help.

Paul Epstein
 
I

Ian Collins

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.
 
S

Salt_Peter

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 help.

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
};
 
A

AnonMail2005

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 help.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top