Thread: Inherited syntax

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    19

    Inherited syntax

    I have been studying the source code for FLTK and I've noticed syntax I've never come across before.

    Code:
    Fl_Button::Fl_Button(int X, int Y, int W, int H, const char *l)
    : Fl_Widget(X,Y,W,H,l) {
    Now in this instance Fl_Button inherits from Fl_Widget so am I correct to assume that :Fl_Widget(X,Y,W,H,l) is just setting the parameters in the Fl_Widget constructor using parameters passed into the Fl_Button constructor (as the Fl_Widget constructor is assumedly called as well) and then the Fl_Button constructor does whatever class specific constructor things..

    Have I got the correct idea here?

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Yes... basically when you initialize a derived class, you can explicitly call the base constructor with the derived class's constructor. This is necessary if the base class doesn't have a default constructor. If it does, the default will be called if no constructor is explicitly called.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    19
    Great, seemed logical enough. Thanks.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Note that you should be using that same syntax to initialize the member variables of the class as well. It is called the initializer list.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM