base class should be explicitly initialized in the copy constructor

This is a discussion on base class should be explicitly initialized in the copy constructor within the C++ Programming forums, part of the General Programming Boards category; anon: To generate the warning, I think this code will suffice. It also demonstrates the reason why the warning is ...

  1. #16
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    anon: To generate the warning, I think this code will suffice. It also demonstrates the reason why the warning is there.
    Interestingly, the MinGW port of g++ 3.4.5 does not emit any warnings at -Wall, the Comeau online compiler does the same, and MSVC8 only warns about an unreferenced formal parameter at /W4. rockstar1707 used the MinGW port of g++ 3.4.5, so this seems inconsistent.

    And yes, in retrospect I interpreted rockstar1707's reported warning message completely wrong
    Last edited by laserlight; 11-20-2007 at 10:33 PM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #17
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    That's what I meant. My example was a case where the warning was useful - because the resulting behaviour was most likely not what was intended.

    But from reading the Boost code that didn't have the problem, I knew that the base was default-initialized anyway, so the implicit behaviour was what was wanted. It's just that, on copy-construction, you typically want to copy-initialize the base, so if you actually do want to default-initialize it (which is what happens when you omit the base in the initializer list), the compiler asks you to do it explicitly - just to make sure you haven't simply forgotten the base.



    laserlight: Have you tried -Wextra? Or perhaps even -Weffc++?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,306
    laserlight: Have you tried -Wextra? Or perhaps even -Weffc++?
    Ah, -Wextra did the trick, though -Weffc++ did not.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User
    Join Date
    Nov 2007
    Posts
    7
    Thanks again for all the answers. I must say that some things are unfortunately beyond my knowledge of C++...

    As I said, for now I'll ignore the warning, since I'm a bit in a hurry with development. But one day I'll try to take care of that as well.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 06:11 PM
  2. Two conceptual questions
    By AntiScience in forum C++ Programming
    Replies: 3
    Last Post: 11-01-2007, 12:36 PM
  3. copy constructor prolbem(??) in a class Name
    By kantze in forum C++ Programming
    Replies: 15
    Last Post: 07-23-2007, 12:07 AM
  4. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 11:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21