I am working through a practice exam for a programming final and I have a question about the way a program calls class constructors. How am I able to tell how many times the constructor is called in a specific program? For example...
Code:
int main(){
String A, B("Examination");
cout << "Enter a string: ";
cin >> A;
cout << "The string you entered was: " << A << endl;
if(A == "Midterm" || A == "Final"){
cout << A << " " << B << endl;
}
}
This is main() is based off a String class interface provided on the sample exam by the instructor. There is a question that asks how many calls to the constructor there are. When I look at this, I see 2 for sure and maybe 1. Where String A and B are declared and I believe where the user inputs data into A. Now, according to the sample exam the answer is 4 and I am not really sure why. Is it perhaps that they are called when they are declared and the when they are outputted? That would be 4 but doesn't really seem right to me.