Thread: mean of the last : in members declaration

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    2

    Unhappy mean of the last : in members declaration

    what is the meaning of the last :class() declaration on the the folowing member function definition.?
    Code:
    CLASSX::CONSTRUCTORX (params, ..) :CLASSY(param2){
    ...
    }
      I know that :
    class CLASSX: public CLASSY
    {
    ...
    CONSTRUCTORX(param,..)
    }
    and
    the class CLASSY have a constructor with one param.
    First I think that it is for call the CLASEY construsctor but, if CLASSY<--CLASSX i suppose that the constructor CLASSY cosntructor is calling by default.
    or not?
    help please!

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The : indicates an initializer list. This is where base class constructors are called and member variables are initialized. If you leave it out, the default constructor for CLASSY will be called, but sometimes you want to or have to call a different constructor than the default constructor. You do that by using the initializer list.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    note that in the same way you can also initialize the member vars
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    2

    Smile Thanks you

    Thanks you, boys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 08:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM