CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 280

Threaded View

  1. #11
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    720
    Well, I don't know what standard says about such situation when you have the first part of hierarchy with non-virtual dtor and the other part with virtual dtor, and trying to delete via some class pointer which has virtual dtor. The point is that it is dangerious to derive a class from some class which has non-virtual dtor.
    Imagine a situation where others can use that class:
    Code:
    typedef vector<POINT> Shape;
    vector<Shape*> all_shapes;
    
    struct Shape1 : Shape
    {
     virtual ~Shape1() {}
    };
    struct Shape2 : Shape
    {
     virtual ~Shape2() {} 
    };
    
    void erase_all_shapes()
    {
     //assume several instances are created  by new and are inserted into all_shapes.
    
     for(Shape::iterator it = all_shapes.begin()....)
       delete *it; //fault at least in MSVC.
    }
    Of course it's a very common case though.
    Last edited by AvDav; November 21st, 2003 at 07:27 PM.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured