1 Replies - 1253 Views - Last Post: 25 December 2009 - 10:17 AM Rate Topic: -----

#1 ice-t  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 104
  • Joined: 26-May 09

Search in a generic linked list

Post icon  Posted 25 December 2009 - 09:47 AM

i want to make a search method to return a node of the list.
the linked list is a generic linked list List<T> and i want to return a node of type T.
this is what I tried.
list<T> *search(People *x) // I tried search(T *s) too
	{
		   list<T> *q = root_list;
		   while(q)
		   {
		  if(q!=NULL && strcmp(q->element,x->name)==0)
			return q;
		  else
		  q = q->next;
		   } 
 return NULL;
	};
  


People is a class which has name as a private.I get this error. Cannot convert People* to const char*, and after trying different syntax sometimes i get People::name member is not accesible

Is This A Good Question/Topic? 0
  • +

Replies To: Search in a generic linked list

#2 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2874
  • View blog
  • Posts: 11,047
  • Joined: 15-July 08

Re: Search in a generic linked list

Posted 25 December 2009 - 10:17 AM

Because name is a private variable, you cannot access it in this way. You will have to make a getter method in the People class, like this:
class People 
{
	private:
		char[] name;
	public:
		 char[] getName() {
			 return name;
		  }
}


Note, I havnt done C++ in a long while and it's probably not char[], but there is the general idea. You may also wish to use the string class: http://www.cprogramm...ial/string.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1