Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3012

Re: Destructors can copying objects

From Ruben Safir <ruben@mrbrklyn.com>
Newsgroups comp.lang.c++
Subject Re: Destructors can copying objects
Date 2011-04-03 03:08 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <in8ob0$ju1$4@reader1.panix.com> (permalink)
References <in76i3$105$2@reader1.panix.com> <in78aa$100$1@tota-refugium.de>

Show all headers | View raw


On Sat, 02 Apr 2011 15:29:26 +0200, Volker Lukas wrote:

> Ruben Safir wrote:
>> I am creating a linked link program which created a segmentation fault
>> and a core at the end of the program. The program is trying to delete
>> an already deleted object, and I can't seem to protect my program from
>> this. I fixed the problem by sending an object to a function by
>> reference rather than by value, but I'm not satisfied with the
>> solution.
> Why is the member "value_" in your Node template a pointer? Maybe you
> forgot to clone this pointer in Nodes copy constructor. This is just a
> guess. You did not post a full compilable example which represents your
> problem, so it is difficult to find the problem. Please post a full
> program.
> 
> Also, there is a list template in the C++ Standard Library. Maybe you
> are coding your own list as an exercise, if not you should consider
> whether using std::list is an option.

I think this outlines the bug

/*
 * =====================================================================================
 *
 *       Filename:  test_del.cpp
 *
 *    Description:  Testing DOuble Deletes
 *
 *        Version:  1.0
 *        Created:  04/02/2011 05:12:24 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME Ruben Safir, 
 *        Company:  NYLXS
 *
 * =====================================================================================
 */



#ifndef  LINKLIST
#define LINKLIST
#include	"linklist.h"
#endif     /* -----  not LINKLIST  ----- */

#include	<iostream>
#include	<fstream>
#include 	<climits>
#include	<stdlib.h>

/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  
 * =====================================================================================
 */


chainlist::List<int> creating_int_list();
void find_all_examples(chainlist::List<int>, int);


int main ( int argc, char *argv[] )
{

   chainlist::List<int> outside = creating_int_list();
   outside.display();
   find_all_examples(outside, 4);

   outside.find_value(4);


   std::cout << "****************************************OUTSIDE**************************************************" << std::endl;
   chainlist::Node<int> * found = outside.cursor();
   std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << outside.cursor() << std::endl;
   found = &(outside.find_next_value(4, *found)); 
   while( found ){ 
      std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << outside.cursor() << std::endl;
      found = &(outside.find_next_value(4, *found));
   }

   return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */


chainlist::List<int> creating_int_list(){
   // chainlist::List<int>  set = new chainlist::List<int>;
   chainlist::List<int>  set;
   srand(12345);
   int ran;
   for(int i = 0; i < 50000; ++i){
      ran=rand();
      set.insert(ran % 101);
   }
   return set;
}

void find_all_examples ( chainlist::List<int> glob, int search_value )
{
   glob.find_value(search_value);
   chainlist::Node<int> * found = glob.cursor();
   std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << glob.cursor() << std::endl;
   found = &(glob.find_next_value(search_value, *found)); 
   while( found ){ 
      std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << glob.cursor() << std::endl;
      found = &(glob.find_next_value(search_value, *found));
   }


   return ;
}		


/

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-02 12:58 +0000
  Re: Destructors can copying objects Volker Lukas <vlukas@gmx.de> - 2011-04-02 15:29 +0200
    Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-03 02:59 +0000
      Re: Destructors can copying objects "Balog Pal" <pasa@lib.hu> - 2011-04-03 11:32 +0200
        Re: Destructors can copying objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-03 12:29 +0100
          Re: Destructors can copying objects Bart van Ingen Schenau <bart@ingen.ddns.info> - 2011-04-04 13:43 +0200
            Re: Destructors can copying objects Michael Doubez <michael.doubez@free.fr> - 2011-04-05 01:26 -0700
          Re: Destructors can copying objects Joshua Maurice <joshuamaurice@gmail.com> - 2011-04-04 14:03 -0700
            Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 21:10 +0000
            Re: Destructors can copying objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-04 22:28 +0100
          Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 21:07 +0000
            Re: Destructors can copying objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-04 22:31 +0100
              Re: Destructors can copying objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-04 22:43 +0100
              Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 22:38 +0000
                Re: Destructors can copying objects Leigh Johnston <leigh@i42.co.uk> - 2011-04-04 23:42 +0100
                Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 22:54 +0000
      Re: Destructors can copying objects James Kanze <james.kanze@gmail.com> - 2011-04-03 10:07 -0700
        Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 21:14 +0000
        Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 21:17 +0000
          Re: Destructors can copying objects LR <lruss@superlink.net> - 2011-04-05 01:52 -0400
    Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-03 03:08 +0000
      Re: Destructors can copying objects Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-03 02:11 -0500
      Re: Destructors can copying objects Volker Lukas <vlukas@gmx.de> - 2011-04-03 12:02 +0200
      Re: Destructors can copying objects Peter Remmers <p.remmers@expires-2011-04-30.arcornews.de> - 2011-04-03 12:14 +0200
        Re: Destructors can copying objects Roberto Waltman <usenet@rwaltman.com> - 2011-04-03 18:16 -0400
          Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-15 23:06 +0000
            Re: Destructors can copying objects LR <lruss@superlink.net> - 2011-04-15 19:19 -0400
        Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-15 23:03 +0000
          Re: Destructors can copying objects "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-16 01:47 +0200
            Re: Destructors can copying objects Peter Remmers <p.remmers@expires-2011-04-30.arcornews.de> - 2011-04-16 13:00 +0200
              Re: Destructors can copying objects "Alf P. Steinbach /Usenet" <alf.p.steinbach+usenet@gmail.com> - 2011-04-16 15:57 +0200
  Re: Destructors can copying objects LR <lruss@superlink.net> - 2011-04-02 09:51 -0400
  Re: Destructors can copying objects Yannick Tremblay <yannick@tremnblay.co.uk> - 2011-04-04 12:56 +0000
    Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-04 21:05 +0000
      Re: Destructors can copying objects Paavo Helde <myfirstname@osa.pri.ee> - 2011-04-04 21:56 -0500
      Re: Destructors can copying objects Yannick Tremblay <yannick@tremnblay.co.uk> - 2011-04-05 11:36 +0000
        Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-05 15:40 +0000
          Re: Destructors can copying objects Sana <sanatakos@gmail.com> - 2011-04-05 10:11 -0700
          Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-05 20:28 +0000
          Re: Destructors can copying objects Yannick Tremblay <yannick@tremnblay.co.uk> - 2011-04-06 11:12 +0000
      Re: Destructors can copying objects drew@furrfu.invalid (Drew Lawson) - 2011-04-05 13:02 +0000
        Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-05 15:51 +0000
          Re: Destructors can copying objects drew@furrfu.invalid (Drew Lawson) - 2011-04-05 17:47 +0000
            Re: Destructors can copying objects Ruben Safir <ruben@mrbrklyn.com> - 2011-04-05 20:25 +0000
              Re: Destructors can copying objects drew@furrfu.invalid (Drew Lawson) - 2011-04-05 20:37 +0000

csiph-web