Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > instance lifeti...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 7 Topic 9390 of 9971
Post > Topic >>

instance lifetime question

by Thomas Taranowski <baringforge@[EMAIL PROTECTED] > Mar 17, 2008 at 01:50 AM

Below I detailed a scenario I'm looking at, and would like to know
what the lifetime of the instance of the string is in the "FooClass
fooClass(string("somestring"))"  is below.  Is the instance of the
string object destroyed after the constructor is called?  Seems like
it would be, but I'm not really sure what the scope of that object
would be.  Is it tem****ary, or would it live until fooClass goes out
of scope, and is destroyed?

Thanks,

Example scenario

    class FooClass {
        public:
        FooClass(string &str) : s(&str)
          {}

        void exec() {
          //manipulate member s
          s.append("X");  //As an example
        }
        private:
        string *s;
    };

func() {
    FooClass fooClass(string("somestring"));

    while(1) {
         //Do stuff with the string
         fooClass.exec();
    }
}



-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 7 Posts in Topic:
instance lifetime question
Thomas Taranowski <bar  2008-03-17 01:50:49 
Re: instance lifetime question
Maciej Sobczak <see.my  2008-03-17 13:23:14 
Re: instance lifetime question
Oncaphillis <oncaphill  2008-03-17 13:25:03 
Re: instance lifetime question
red floyd <no.spam@[EM  2008-03-17 14:12:56 
Re: instance lifetime question
sean_in_raleigh@[EMAIL PR  2008-03-17 14:12:54 
Re: instance lifetime question
lollinus@[EMAIL PROTECTED  2008-03-17 14:12:57 
Re: instance lifetime question
Ron Natalie <ron@[EMAI  2008-03-17 14:12:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Sep 4 23:57:45 CDT 2008.