PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Getting hold of parameters in constructor
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Getting hold of parameters in constructor

Réponse
 
LinkBack Outils de la discussion
Vieux 05/02/2008, 05h42   #1
pauldepstein@att.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Getting hold of parameters in constructor

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
  Réponse avec citation
Vieux 05/02/2008, 05h44   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting hold of parameters in constructor

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.
  Réponse avec citation
Vieux 05/02/2008, 07h25   #3
Salt_Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting hold of parameters in constructor

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

  Réponse avec citation
Vieux 05/02/2008, 15h41   #4
AnonMail2005@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09758 seconds with 12 queries