I need help in initialization list/constructor in abstraction

M

Mononoke

Hi All
I need help 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)
 
S

Saeed Amrollahi

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

Salt_Peter

Hi All
I need help 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 );
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top