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 17-Nov-2006, 23:25
FFCD FFCD is offline
New Member
 
Join Date: Oct 2006
Posts: 25
FFCD is on a distinguished road

Iterator,container,copy Lost


I have two questions that im so lost with.

First question is about a copy constructor, how do i makes a copy of the Entry container from the object parameter.

CPP / C++ / C Code:
MediaCatDb::MediaCatDb(const MediaCatDb& mediaCatDb):_entries(NULL)
{
}

and i have two remove functions The first remove function removes based on an Entry object parameter. The object is searched for in the database and removed if found. The second remove function removes an entry from the database referred to by an iterator object.

First remove function
CPP / C++ / C Code:
void MediaCatDb::remove(const Entry& entry)
{
	//ME
	list<Entry>::iterator it;
	
	if ((it = find(_entries.begin(), _entries.end(), entry)) != _entries.end() )
	{
		_entries.remove(entry);
		cout << "Deleted" << endl;
	}
	else
	{
		cout << "Entry not found" << endl  ;
	}

}

am lost on how to do this remove function??

CPP / C++ / C Code:
void MediaCatDb::remove(MediaCatDb::iterator it)
{
		

}

Any comments and help much thanked.
Last edited by LuciWiz : 18-Nov-2006 at 14:04. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 22-Nov-2006, 00:15
FFCD FFCD is offline
New Member
 
Join Date: Oct 2006
Posts: 25
FFCD is on a distinguished road

Re: Iterator,container,copy Lost


I have done teh copy constructor is this right??

CPP / C++ / C Code:
MediaCatDb::MediaCatDb(const MediaCatDb& mediaCatDb):_entries(NULL)
{
	_entries = mediaCatDb._entries;

}
  #3  
Old 22-Nov-2006, 02:23
amad1337's Avatar
amad1337 amad1337 is offline
Junior Member
 
Join Date: Dec 2004
Posts: 54
amad1337 will become famous soon enough
Thumbs up

Re: Iterator,container,copy Lost


Quote:
Originally Posted by FFCD
am lost on how to do this remove function??
CPP / C++ / C Code:
void MediaCatDb::remove(MediaCatDb::iterator it)
{
         MediaCatDb::iterator tmp;
	//This will call the copy constructor
	MediaCatDb db =  *it;
	

	if ((tmp = find(_entries.begin(), _entries.end(), db)) != _entries.end() )
	{
		_entries.remove(db);
		cout << "Deleted" << endl;
	}
	else
	{
		cout << "Entry not found" << endl  ;
	}	

}

Your copy constructor is seem to be right.
  #4  
Old 22-Nov-2006, 03:33
FFCD FFCD is offline
New Member
 
Join Date: Oct 2006
Posts: 25
FFCD is on a distinguished road

Re: Iterator,container,copy Lost


Thank you,
  #5  
Old 22-Nov-2006, 03:51
FFCD FFCD is offline
New Member
 
Join Date: Oct 2006
Posts: 25
FFCD is on a distinguished road

Re: Iterator,container,copy Lost


I dont think that worked because i keep on getting errors say that " error C2440: 'initializing' : cannot convert from 'Entry' to 'MediaCatDb'
1> No constructor could take the source type, or constructor overload resolution was ambiguous " and " error C2664: 'std::list<_Ty>::remove' : cannot convert parameter 1 from 'MediaCatDb' to 'const Entry &'
1> with
1> [
1> _Ty=Entry
1> ]
1> Reason: cannot convert from 'MediaCatDb' to 'const Entry'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called " do you know what this could mean??
Thanks
  #6  
Old 22-Nov-2006, 04:59
amad1337's Avatar
amad1337 amad1337 is offline
Junior Member
 
Join Date: Dec 2004
Posts: 54
amad1337 will become famous soon enough

Re: Iterator,container,copy Lost


Sorry i wasn't awake try this one
CPP / C++ / C Code:
void MediaCatDb::remove(list<Entry>::iterator it)
{
        
	

	if ((it = find(_entries.begin(), _entries.end(), it)) != _entries.end() )
	{
		_entries.remove(*it);
		cout << "Deleted" << endl;
	}
	else
	{
		cout << "Entry not found" << endl  ;
	}	

}

Just a remark: if you already have i member function looking like the one under here you
dont need the above if you call the member function under here with argument like remove(*it). This will cause
*it implicitly to convet to Entry reference object.
CPP / C++ / C Code:
void MediaCatDb::remove(const Entry& entry)
{
	//ME
	list<Entry>::iterator it;
	
	if ((it = find(_entries.begin(), _entries.end(), entry)) != _entries.end() )
	{
		_entries.remove(entry);
		cout << "Deleted" << endl;
	}
	else
	{
		cout << "Entry not found" << endl  ;
	}

}
  #7  
Old 23-Nov-2006, 06:48
FFCD FFCD is offline
New Member
 
Join Date: Oct 2006
Posts: 25
FFCD is on a distinguished road

Re: Iterator,container,copy Lost


It still not working error : " no operator found which takes a right-hand operand of type 'const std::list<_Ty>::_Iterator<_Secure_validation>' (or there is no acceptable conversion)
1> with
1> [
1> _Ty=Entry,
1> _Secure_validation=true
1> ]"

my code
Code:
MediaCatDb::MediaCatDb(){} MediaCatDb::MediaCatDb(const MediaCatDb& db):_entries(NULL) { _entries = db._entries; } void MediaCatDb::add(const Entry& entry) { list<Entry>::iterator it; if ((it = find(_entries.begin(), _entries.end(), entry)) != _entries.end() ) { cout << "Entry present" << endl; } else { _entries.push_back(entry); } } void MediaCatDb::remove(const Entry& entry) { list<Entry>::iterator it; if ((it = find(_entries.begin(), _entries.end(), entry)) != _entries.end() ) { _entries.remove(entry); cout << "Deleted" << endl; } else { cout << "Entry not found" << endl; } } void MediaCatDb::remove(list<Entry>::iterator it) { if ((it = find(_entries.begin(), _entries.end(), it)) != _entries.end() ) { _entries.remove(*it); cout << "Deleted" << endl; } else { cout << "Entry not found" << endl ; } } MediaCatDb::iterator MediaCatDb::begin() { return iterator(_entries.begin()); } MediaCatDb::const_iterator MediaCatDb::begin() const { return const_iterator(_entries.begin()); } MediaCatDb::iterator MediaCatDb::end() { return iterator(_entries.end()); } MediaCatDb::const_iterator MediaCatDb::end() const { return const_iterator(_entries.end()); }

in the header file the following is declared

Code:
class MediaCatDb { typedef list<Entry> Container; Container _entries; public: typedef Container::iterator iterator; typedef Container::const_iterator const_iterator;
  #8  
Old 28-Nov-2006, 17:47
FFCD FFCD is offline
New Member
 
Join Date: Oct 2006
Posts: 25
FFCD is on a distinguished road

Re: Iterator,container,copy Lost


Sloved my prob throught out was nto using this

Container::iterator it = _entries.begin();
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

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
help in retrieveItem using a list... I'm lost febrarierose C++ Forum 3 29-May-2006 16:03
All my important documents may be lost! mr5 Computer Software Forum - Windows 2 15-Sep-2005 04:12
lost me scrollbars! pixienick MS Visual C++ / MFC Forum 1 05-Sep-2005 09:19
Checking source codes of image, audio and video files onauc C Programming Language 5 26-Feb-2005 22:47
Session Variables lost by Mac? shrdlu MySQL / PHP Forum 1 06-Mar-2004 23:55

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

All times are GMT -6. The time now is 05:57.


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