Thread: question regarding consrtuctor calls

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    7

    question regarding constructor calls

    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.
    Last edited by alt234; 12-11-2005 at 03:17 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM