|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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) |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
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 ); |
|
![]() |
| Outils de la discussion | |
|
|