Thread: Setting default param vals?

  1. #1
    Registered User
    Join Date
    Nov 2008

    Setting default param vals?

    I'm looking through some code and see
    void myclass::myfunc():
    I'm having trouble finding anything on google that tells me what this is. What is the purpose of this syntax? Are these optional paramaters that are being given default values?

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    It is called a initializer list. Basically, it initializes member variables with a given value.
    (This is different from assigning since assigning calls the assignment operator and initialization will call a constructor.)
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2010
    This like a incorrect attempt of using initialization list. The reason it is incorrect is that initialization lists only work with constructors not member functions.
    void myclass::myclass(): a(0), b("hello")
    Would be correct if your class had a variable named a and a string variable named b.
    See this link on initialization lists.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing ... as a param?
    By homer_3 in forum C Programming
    Replies: 3
    Last Post: 06-29-2010, 12:53 AM
  2. why if with break skips false vals here?
    By kocika73 in forum C Programming
    Replies: 2
    Last Post: 11-10-2004, 03:08 PM
  3. Getting File param name
    By CodeMonkey in forum Windows Programming
    Replies: 10
    Last Post: 09-04-2002, 07:35 PM
  4. Setting default value for LISTBOX
    By paulf in forum Windows Programming
    Replies: 0
    Last Post: 04-19-2002, 12:58 AM
  5. setting default font to draw all further controls with
    By alandrums in forum Windows Programming
    Replies: 0
    Last Post: 12-03-2001, 10:31 PM