This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problems with delete after a forward reference.


Hello,
    I have found a difference between Visual C++ and gcc 2.95.2.  The short
version is that if you do a forward reference of a class you can not issue a
delete on an object of that class in gcc but you can in Visual C++.  I am
looking to see if there is a flag that might allow me to do this or
something.  I do not know if it is a bug because I am not sure of what the
standard says.

The longer version is, I have two classes (say foo and bar) which both
include a pointer template called countedpointer.  When the count of people
using the pointer goes to zero it does  delete on the object in the pointer.
Since all of the references in foo, bar and the countedpointer are pointer
references you can use forward declarations to get around this.  below are
not the real classes but it should explain my problem

template <class pointedto>
 class countedpointer<pointedto>
   {
      public:
       countedpointer<pointedto>(): value = NULL,count=0 
         {
         }
       destruct()
         {
            if(count)
             {
               count --;
               if (count == 0)
                {
                  delete value;
                  value = NULL;
                 }
           }
     private:
         pointedto *value;
         int count;
            
  }

class foo;

class bar
 {
    private:
	countedpointer<foo> otherpart();
 }

class foo
 {
    private
          countedpointer<bar> otherpart;
 }

   This will compile on Visual C++ because the delete is looked at as a
pointer / reference type of function and does not need to know the size of
either foo or bar.  In GCC it has an error because it does not know the size
of the thing that value is pointing to and wants to know that before the
delete is processed.  I am not sure it is a gnu bug but I would think it is
(but that is of course because I want this to work ;-)

Tim Gibney
Kazan Software.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]