Advertisement

03.01.2006 at 04:54PM PST, ID: 21757240
[x]
Attachment Details

Constructing an object inside a loop

Asked by chsalvia in C++ Programming Language

Tags: loop, inside, object

If you have a loop like:

int i = 0;
while (i < 100)
{
     MyClass mc = "abcd";
     // do something...
     i++;
}

In each iteration, it calls the constructor for class MyClass.  Does it also automatically call the destructor, and remove MyClass from memory before continuing to the next iteration?  

I would think it does, since the object "mc" is named the same thing in each iteration of course.Start Free Trial
 
 
[+][-]03.01.2006 at 05:09PM PST, ID: 16081064

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.01.2006 at 06:56PM PST, ID: 16081553

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.01.2006 at 11:08PM PST, ID: 16082507

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.01.2006 at 11:25PM PST, ID: 16082571

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.01.2006 at 11:27PM PST, ID: 16082580

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.02.2006 at 02:45AM PST, ID: 16083504

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.02.2006 at 06:55AM PST, ID: 16085121

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.02.2006 at 12:14PM PST, ID: 16088330

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.02.2006 at 12:37PM PST, ID: 16088564

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Tags: loop, inside, object
Sign Up Now!
Solution Provided By: dbkruger
Participating Experts: 6
Solution Grade: A
 
 
[+][-]03.02.2006 at 12:41PM PST, ID: 16088603

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32