k, i have looked through 2 different books and my instructor doesnt have the greatest knack for explaining things.
Can anyone briefly explain the point of using a constructor within a class? Is it just a required piece of code needed for classes? Or is it just an attempt at confusing the compiler for giving such incredibly odd and annoying error messages?
i understand that a constructor is a member of the class that has the same name but does not return anything, but i cant find out why a constructor is necessary. any help is appreciated. :)
In a constructor you would initalize all the member variables to certain values. Basically a constructor is what allows you to put an object into a known state.
The constuctor of a class is called automatically when the class object is created. For this reason, the constuctor is a good place to initialize variables and do any other setup that is necessary for your class.