Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > I need help in initialization list/constructor in abstraction

Reply
Thread Tools

I need help in initialization list/constructor in abstraction

 
 
Mononoke
Guest
Posts: n/a
 
      12-11-2007
Hi All
I need help in initialization list/constructor in abstraction

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

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

class CHighTechClothublic 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)



 
Reply With Quote
 
 
 
 
Saeed Amrollahi
Guest
Posts: n/a
 
      12-11-2007
On Dec 11, 2:17 pm, Mononoke <(E-Mail Removed)> wrote:
> Hi All
> I need help 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 CMyClothublic ICloth
> {
> CMyCloth(EColor color, ESize size,EStatus status,EType type,EQuality
> quality);
> ...........
>
> }

};
>
> class CHighTechClothublic 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 CHighTechClothublic CMyCloth
{
public:
CHighTechCloth() : CMyTech
ICloth::EC_RED,
ICloth::CS_SMALL,
ICloth::CST_NEWCLOTH,
ICloth::CT_EYEGLASSES,
ICloth::EQ_LOW)

}

Try more

S. Amrollahi
 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      12-11-2007
On Dec 11, 6:17 am, Mononoke <(E-Mail Removed)> wrote:
> Hi All
> I need help in initialization list/constructor in abstraction
>
> I have abstract base class -
> class ICloth
> {
> ICloth();
> ...........
>
> }


}; // its a class declaration

>
> class CMyClothublic 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 CHighTechClothublic 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 );

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what's the difference between value-initialization and default-initialization? Jess C++ 23 05-04-2007 03:03 AM
array initialization in initialization list. toton C++ 5 09-28-2006 05:13 PM
Initialization of non-integral type in initialization list anongroupaccount@googlemail.com C++ 6 12-11-2005 09:51 PM
Initialization via ctor vs. initialization via assignment Matthias Kaeppler C++ 2 07-18-2005 04:25 PM
Default Initialization Vs. Value Initialization JKop C++ 10 09-22-2004 07:26 PM



Advertisments