CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 19 of 19
  1. #16
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    Re: Using delete on an object without new

    Quote Originally Posted by Paul McKenzie View Post
    there is no way to delete something that isn't a pointer value
    Well this could be what he's after, but delete on a stack based object has to be undefined behaviour I think.
    Code:
    class X
    {
    public:
    operator X*()
    {
    returnthis;
    }
    };
    int main()
    {
    X x;
    delete x;
    }
    
    PS:- How comes copy/paste from my msvc9 express ruins all indentation. Ive set to use spaces instead of tabs like on all previous versions but my code never cut/pastes properly??
    Get Microsoft Visual C++ Express here or CodeBlocks here.
    Get STLFilt here to radically improve error messages when using the STL.
    Get these two can't live without C++ libraries, BOOST here and Loki here.
    Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors.
    Always use [code] code tags [/code] to make code legible and preserve indentation.
    Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

  2. #17
    Join Date
    Nov 2008
    Location
    Netherlands
    Posts
    77

    Re: Using delete on an object without new

    maybe

    Code:
    class X
    {
    int* wuahaha;
    public:
    X()
    :wuahaha(new int)
    {}
    operator int*()
    {
    return wuahaha;
    }
    };
    int main()
    {
    X x;
    delete x;
    }

  3. #18
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,033

    Re: Using delete on an object without new

    Quote Originally Posted by Plasmator
    Like in the typedef example demonstrated by Paul, the invocation of scalar/vector operator delete on a null pointer is guaranteed to be a logical no-op.
    Ah yes, I think your idea "works" best.

    Now, hopefully Gorbo can just submit this and move on to more useful things.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  4. #19
    Join Date
    Oct 2008
    Posts
    45

    Re: Using delete on an object without new

    Ok based on what laserlight and Plasmator wrote i made something similar to the requirements so thanks everyone and especially laserlight and Plasmator

    cya
    For now

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



HTML5 Development Center

Click Here to Expand Forum to Full Width