GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-May-2008, 01:55
hungle hungle is offline
New Member
 
Join Date: May 2008
Posts: 3
hungle is on a distinguished road

How to delete a record in array of pointers to class


Hi,

I have made a class that contain an array of pointers to class "CFigure"
I want to create a function that get an index and delete a record in that index from the array.
Can you help me please.

CPP / C++ / C Code:
Arrays.h

#ifndef __ARRAYS_H__
#define __ARRAYS_H__
#include <windows.h>
#include "Figure.h"
#include <iostream>
using std::ostream;
using std::istream;

class Array
{  
public:
	CFigure *FigArray[100];
	Array();
	~Array();
	int getSize() const;
	CFigure* &operator[]( int );
             void Remove(int);

private:
   int size; 
   CFigure *ptr;
   
}; 

#endif



Arrays.cpp

#include "Figure.h"
#include <iostream>
#include "Arrays.h"


Array::Array()
{
	size =0;
	ptr=FigArray;
}

Array::~Array()
{
   delete [] ptr;
} 

int Array::getSize() const
{
   return size;
}

CFigure* &Array::operator[]( int subscript )
{
	return this->FigArray[subscript]; // reference return
}


void Remove(int j);
{
  // ??????
}

  #2  
Old 12-May-2008, 08:30
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: How to delete a record in array of pointers to class


CPP / C++ / C Code:
class Array
{  
public:
	//CFigure *FigArray[100];
	CFigure **FigArray;

//......
};

void Array::Remove(int j);
{
  // Validate j
  if(j < 0 || j >= size) return;
  
  CFigure** temp = new CFigure*[size-1];
  for(int i=0;i<j;++i) temp[i] = FigArray[i];
  for(i=j+1;i<size;++i) temp[i-1] = FigArray[i];
  delete [] FigArray;
  FigArray = temp;
  --size; 

}
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort an array of structures sassy99 C Programming Language 10 15-Feb-2007 08:46
Hard drive/CPU Diagnoses Issues binarybug Computer Hardware Forum 1 22-Jan-2007 20:23
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31
[Tutorial] Pointers in C (Part I) Stack Overflow C Programming Language 1 08-Apr-2005 19:35

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 08:33.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.