I need help in initialization list/constructor in abstraction

Discussion in 'C++' started by Mononoke, Dec 11, 2007.

  1. Mononoke

    Mononoke Guest

    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)
    Mononoke, Dec 11, 2007
    #1
    1. Advertising

  2. On Dec 11, 2:17 pm, Mononoke <> 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 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
    Saeed Amrollahi, Dec 11, 2007
    #2
    1. Advertising

  3. Mononoke

    Salt_Peter Guest

    On Dec 11, 6:17 am, Mononoke <> 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 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 );
    Salt_Peter, Dec 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    6
    Views:
    451
    Ron Natalie
    Dec 11, 2005
  2. toton
    Replies:
    5
    Views:
    921
    Victor Bazarov
    Sep 28, 2006
  3. Generic Usenet Account
    Replies:
    10
    Views:
    2,204
  4. aaragon
    Replies:
    2
    Views:
    607
    James Kanze
    Nov 2, 2008
  5. balaji
    Replies:
    3
    Views:
    926
    Jens Thoms Toerring
    Aug 10, 2011
Loading...

Share This Page