Inherited syntax

This is a discussion on Inherited syntax within the C++ Programming forums, part of the General Programming Boards category; 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 ...

  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,069
    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,318
    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, 04:45 PM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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