Interview question.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?utf-8?B?5YiY5piK?=

    Interview question.

    Name two cases where you MUST use initialization list as opposed to
    assignment in constructors.

  • Victor Bazarov

    #2
    Re: Interview question.

    ?? wrote:
    Name two cases where you MUST use initialization list as opposed to
    assignment in constructors.
    Think of what cannot be constructed without initialisation. What do
    you initialise in the initialisation list? Base classes and members,
    right? So, what would require a class to be placed in the initialiser
    list? What would require a member to be placed there?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • Gianni Mariani

      #3
      Re: Interview question.

      刘昊 wrote:
      Name two cases where you MUST use initialization list as opposed to
      assignment in constructors.
      Only 2 ?


      Comment

      • Victor Bazarov

        #4
        Re: Interview question.

        Gianni Mariani wrote:
        ?? wrote:
        >Name two cases where you MUST use initialization list as opposed to
        >assignment in constructors.
        >
        Only 2 ?
        Only 2 that the interviewER could think of, I take it.


        Comment

        • Jim Langston

          #5
          Re: Interview question.

          "??" <leomayleomay@g mail.comwrote in message
          news:1187009756 .560911.236380@ i13g2000prf.goo glegroups.com.. .
          Name two cases where you MUST use initialization list as opposed to
          assignment in constructors.
          References and Base Classes are two.


          Comment

          • AnonMail2005@gmail.com

            #6
            Re: Interview question.

            On Aug 13, 11:37 am, "Jim Langston" <tazmas...@rock etmail.comwrote :
            "??" <leomayleo...@g mail.comwrote in message
            >
            news:1187009756 .560911.236380@ i13g2000prf.goo glegroups.com.. .
            >
            Name two cases where you MUST use initialization list as opposed to
            assignment in constructors.
            >
            References and Base Classes are two.
            Also, I believe constant members must also be initialized in the
            intialization
            list.

            Comment

            • Ron Natalie

              #7
              Re: Interview question.

              Alf P. Steinbach wrote:
              2. Member variables with user-defined constructors.
              Actually, just those missing a default constructor.

              Comment

              • Gianni Mariani

                #8
                Re: Interview question.

                Alf P. Steinbach wrote:
                * Jim Langston:
                >"??" <leomayleomay@g mail.comwrote in message
                >news:118700975 6.560911.236380 @i13g2000prf.go oglegroups.com. ..
                >>Name two cases where you MUST use initialization list as opposed to
                >>assignment in constructors.
                >>
                >References and Base Classes are two.
                >
                Language level technical reasons:
                >
                1. Base classes.
                2. Member variables with user-defined constructors.
                3. Member variables with inaccessible or inappropriate assignment operator.
                4. "const" member variables.
                5. Reference members.
                >
                Other technical reasons:
                >
                6. When there are dependencies between member variables so that
                some must be initialized before one where 1...5 applies.
                >
                Non-technical reasons:
                >
                7. When the coding guideline or other authority says so.
                >
                Number 8 is a "meta" reason for meta programming.

                8. When initializing an member of a template class that you cannot
                determine what type it will be because not doing so will result in
                potential problems either with uninitialized POD's.

                i.e.

                template <typename Tstruct X
                {
                T v;
                X() : v() {}
                };

                X<inti; // i.v is initialized to zero
                X<std::strings ; // s.v is initialized to ""

                I suppose it's not really a MUST ...

                Comment

                Working...