So i haven't figured out what the point of constructors are i am just learning C++ and am seriously having trouble with it, i do not get why...well i kind of get default constructors because it initializes the variables but what about a constructor with arguments and the member function
TheLittleEngine 1 Newbie Poster
Recommended Answers
Jump to PostMethod that get called automatically when objects get created from Class. You can perfom initialization there
class Person{ public int height, weight; //Ctor - Can be more than one aka overloaded public void Person(){ //Do init here height = 100; weight = 250; } };
Jump to Postoh so when there are multiple constructors you are overloading the constructors
Constructor is a "special" method. It can be overloaded like any other method. Note that Constructor should not return anything!
Jump to PostAlso if you create a constructor for your class don't forget to also provide a default constructor. A default constructor is only provided if there are no constructors defined.
All 10 Replies
Stefano Mtangoo 455 Senior Poster
TheLittleEngine 1 Newbie Poster
Stefano Mtangoo 455 Senior Poster
NathanOliver 429 Veteran Poster Featured Poster
TheLittleEngine 1 Newbie Poster
TheLittleEngine 1 Newbie Poster
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
m4ster_r0shi 142 Posting Whiz in Training
TheLittleEngine 1 Newbie Poster
Stefano Mtangoo 455 Senior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.