When is an unnamed automatic variable destroyed?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven T. Hatton

    #1

    When is an unnamed automatic variable destroyed?

    In this code, when will (should) Xfromer::releas e be called?
    struct C {
    C(const char* c) { f = Xformer::xform( c); }
    ~C() { Xformer::releas e(f); }
    const F* get() const { return f; }
    F* f;
    };

    void fun(const char* c) {
    F* foo = C(c).get();
    bar(foo);
    baz();
    }

    --
    NOUN:1. Money or property bequeathed to another by will. 2. Something handed
    down from an ancestor or a predecessor or from the past: a legacy of
    religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
    from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/
  • Victor Bazarov

    #2
    Re: When is an unnamed automatic variable destroyed?

    Steven T. Hatton wrote:[color=blue]
    > In this code, when will (should) Xfromer::releas e be called?
    > struct C {
    > C(const char* c) { f = Xformer::xform( c); }
    > ~C() { Xformer::releas e(f); }
    > const F* get() const { return f; }
    > F* f;
    > };
    >
    > void fun(const char* c) {
    > F* foo = C(c).get();[/color]

    The temporary that is used in the expression to initialise 'foo' will be
    destroyed at the end of 'foo's initialisation. 'Xformer::relea se' should
    be called as part of the destruction of the temporary, right after 'foo'
    is initialised.
    [color=blue]
    > bar(foo);
    > baz();
    > }
    >[/color]

    V
    --
    Please remove capital As from my address when replying by mail

    Comment

    • Steven T. Hatton

      #3
      Re: When is an unnamed automatic variable destroyed?

      Victor Bazarov wrote:
      [color=blue]
      > Steven T. Hatton wrote:[color=green]
      >> In this code, when will (should) Xfromer::releas e be called?
      >> struct C {
      >> C(const char* c) { f = Xformer::xform( c); }
      >> ~C() { Xformer::releas e(f); }
      >> const F* get() const { return f; }
      >> F* f;
      >> };
      >>
      >> void fun(const char* c) {
      >> F* foo = C(c).get();[/color]
      >
      > The temporary that is used in the expression to initialise 'foo' will be
      > destroyed at the end of 'foo's initialisation. 'Xformer::relea se' should
      > be called as part of the destruction of the temporary, right after 'foo'
      > is initialised.
      >[color=green]
      >> bar(foo);
      >> baz();
      >> }
      >>[/color]
      >
      > V[/color]

      http://tinyurl.com/oz2m6

      --
      NOUN:1. Money or property bequeathed to another by will. 2. Something handed
      down from an ancestor or a predecessor or from the past: a legacy of
      religious freedom. ETYMOLOGY: MidE legacie, office of a deputy, from OF,
      from ML legatia, from L legare, to depute, bequeath. www.bartleby.com/61/

      Comment

      • Victor Bazarov

        #4
        Re: When is an unnamed automatic variable destroyed?

        Steven T. Hatton wrote:[color=blue]
        > Victor Bazarov wrote:
        >
        >[color=green]
        >>Steven T. Hatton wrote:
        >>[color=darkred]
        >>>In this code, when will (should) Xfromer::releas e be called?
        >>>[...][/color]
        >>
        >>The temporary that is used [...]
        >>
        >>V[/color]
        >
        >
        > http://tinyurl.com/oz2m6
        > http://koolkat2.cs.rice.edu/cgi-bin/...OMDocument.cpp[/color]

        Uh... Did you mean to supply some explanation to those links?

        Comment

        Working...