Let's say I have a struct defined as:
typedef
struct number{
int areaCode;
int prefix;
int suffix;
} PhoneNumber;
When I create an instance of this struct, if I use the following syntax:
PhoneNumber homePhone = {858, 555, 1234};
...which constructor is it calling? The default constructor, or the copy constructor, or none at all because it's not calling 'new'?
The real purpose of this question is to figure out how I can add a fourth field. So I want to re-define my struct as:
typedef
struct number{
int areaCode;
int prefix;
int suffix;
int extension; // NEW FIELD INTRODUCED
} PhoneNumber;
So now, I can create new PhoneNumber objects with FOUR fields:
PhoneNumber officePhone = {858, 555, 6789, 777}
However, I have hundreds of these PhoneNumber instances already created with only 3 fields (xxx, xxx, xxxx). So I don't want to go through and modify EVERY single instantiation of my PhoneNumber object that is already defined. I want to be able to leave those alone, but still be able to create new phone number instances with FOUR fields. So I am trying to figure out how I can overwrite the constructor so that my existing three-parameter instantiations will not break, but it will also support my new four-parameter instantiations.
When I try to define an overriding default constructor that takes 3 fields and sets the fourth to a default value '0', I get errors (in the instantiation part of the code, not the constructor definition) complaining that my object must be initialized by constructor, not by {...}. So it seems that if I do override the default constructor, I can no longer use curly braces to create my new objects?
Sorry if this strays away from the original questions completely.