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 > I need in initialization list/constructor in abstraction
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
I need in initialization list/constructor in abstraction

Réponse
 
LinkBack Outils de la discussion
Vieux 11/12/2007, 11h17   #1
Mononoke
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut I need in initialization list/constructor in abstraction

Hi All
I need in initialization list/constructor in abstraction

I have abstract base class -
class ICloth
{
ICloth();
............
}

class CMyCloth:public ICloth
{
CMyCloth(EColor color, ESize size,EStatus status,EType type,EQuality
quality);
............
}

class CHighTechCloth:public CMyCloth
{
public:
CHighTechCloth();
....................
}

/////
now in main I try to create CHighTechCloth object, what do I do wrong?


CHighTechCloth* pMyNewCloth = new
CHighTechCloth():ICloth(ICloth::EC_RED,
ICloth::CS_SMALL,
ICloth::CST_NEWCLOTH,
ICloth::CT_EYEGLASSES,
ICloth::EQ_LOW)



  Réponse avec citation
Vieux 11/12/2007, 11h47   #2
Saeed Amrollahi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I need in initialization list/constructor in abstraction

On Dec 11, 2:17 pm, Mononoke <Taly.Ga...@gmail.com> wrote:
> Hi All
> I need in initialization list/constructor in abstraction
>
> I have abstract base class -
> class ICloth
> {
> ICloth();
> ...........

I think it is better to use single line comment // rather than ....
>
> }

};
class declaration is terminated by ;
>
> class CMyCloth:public ICloth
> {
> CMyCloth(EColor color, ESize size,EStatus status,EType type,EQuality
> quality);
> ...........
>
> }

};
>
> class CHighTechCloth:public CMyCloth
> {
> public:
> CHighTechCloth();
> ...................
>
> }

};
>
> /////
> now in main I try to create CHighTechCloth object, what do I do wrong?
>
> CHighTechCloth* pMyNewCloth = new
> CHighTechCloth():ICloth(ICloth::EC_RED,
> ICloth::CS_SMALL,
> ICloth::CST_NEWCLOTH,
> ICloth::CT_EYEGLASSES,
> ICloth::EQ_LOW)


You should use inlialization list in class declaration/definition.
Also you should use immediate base class constructor for
initialization.

class CHighTechCloth:public CMyCloth
{
public:
CHighTechCloth() : CMyTech
ICloth::EC_RED,
ICloth::CS_SMALL,
ICloth::CST_NEWCLOTH,
ICloth::CT_EYEGLASSES,
ICloth::EQ_LOW)

}

Try more

S. Amrollahi
  Réponse avec citation
Vieux 11/12/2007, 16h19   #3
Salt_Peter
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: I need in initialization list/constructor in abstraction

On Dec 11, 6:17 am, Mononoke <Taly.Ga...@gmail.com> wrote:
> Hi All
> I need in initialization list/constructor in abstraction
>
> I have abstract base class -
> class ICloth
> {
> ICloth();
> ...........
>
> }


}; // its a class declaration

>
> class CMyCloth:public ICloth
> {
> CMyCloth(EColor color, ESize size,EStatus status,EType type,EQuality
> quality);


consider using const parameters,
in the case these parameter types are not primitives (ie: complex
classes), use const references instead.

CMyCloth(const EColor, const ESize, const EStatus, const
EType, const EQuality);

> ...........
>
> }


}; // its a class declaration

>
> class CHighTechCloth:public CMyCloth
> {
> public:
> CHighTechCloth();


CHighTechCloth( const EColor,
const ESize,
const EStatus,
const EType,
const EQuality ); // declaration

> ...................
>
> }


}; // its a class declaration

You could supply both a default ctor and a parametized ctor if that
fits the bill.

// default ctor definition
CHighTechCloth::CHighTechCloth() : CMyCloth( EC_RED,
CS_SMALL,
CST_NEWCLOTH,
EQ_LOW )
{
} // its a definition, no semi-colon


// parametized ctor definition
CHighTechCloth::CHighTechCloth( const EColor color,
const ESize size,
const EStatus status,
const EType type,
const EQuality quality )
: CMyCloth (color, size, status,
quality)
{
} // definition

>
> /////
> now in main I try to create CHighTechCloth object, what do I do wrong?
>
> CHighTechCloth* pMyNewCloth = new
> CHighTechCloth():ICloth(ICloth::EC_RED,
> ICloth::CS_SMALL,
> ICloth::CST_NEWCLOTH,
> ICloth::CT_EYEGLASSES,
> ICloth::EQ_LOW)


CHighTechCloth* pMyNewCloth = new CHighTechCloth;

CHighTechCloth* p_hitechcloth = new CHighTechCloth( ICloth::EC_RED,
ICloth::CS_SMALL,

ICloth::CST_NEWCLOTH,

ICloth::CT_EYEGLASSES,
ICloth::EQ_LOW );

  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 17h45.


É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,11924 seconds with 11 queries