#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Location
    Hyderabad
    Posts
    17
    Rep Power
    0

    Constructor Functions


    Hi,

    Why Constructor function has same name as Class? Is there any valid point ? Why it should not have different name?


    Suri
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    793
    A contructor function has the same name as the class because it is to be called when the object is created. This is done so that you don't have to call a seperate function at that time, just create the object and it calls this function automatically.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    if you donīt like it, try another programming language.

    in delphi eg. you can name the constructor / destructor whatever you want... the result is, that unlike C++, you have to tell which constructor to use:

    myObject:=TClass.Create();
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Posts
    37
    Rep Power
    12
    I like it one less line of code to type....::D

IMN logo majestic logo threadwatch logo seochat tools logo