LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 09-08-2009, 11:51 PM   #1
Corps
LQ Newbie
 
Registered: Aug 2009
Posts: 9

Rep: Reputation: 0
Linked List with Iterator


I'm trying to write a linked list for my Smart Pointer class and i have no problem writing one by itself for a specific class such as int and it will even store my SmartPtr<int> if its made as a linkedlist<long int> because i save a reference to them but it's when i get to classes i can't do anything with. My question is is there anyway to get a reference for a built class and possibly store it as an int.
 
Old 09-09-2009, 06:15 AM   #2
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Squeeze (Fluxbox WM)
Posts: 1,331
Blog Entries: 45

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
It is certainly possible to convert a reference to an object (not a class) to an integer, but this is undesirable (because it breaks all the type checking).

The reason for using templates is to avoid this kind of thing. Wouldn't you just declare something like "linkedlist<SmartPtr<int> >"?
 
Old 09-09-2009, 11:22 PM   #3
Corps
LQ Newbie
 
Registered: Aug 2009
Posts: 9

Original Poster
Rep: Reputation: 0
Yeah well that would work for the ints but i have smart pointers pointing to classes iv made aswell i can get it to work for ints chars etc. but not my classes
 
Old 09-10-2009, 12:46 AM   #4
neonsignal
Senior Member
 
Registered: Jan 2005
Location: Melbourne, Australia
Distribution: Debian Squeeze (Fluxbox WM)
Posts: 1,331
Blog Entries: 45

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I think you are saying that your code fails for the case "linkedlist<SmartPtr<MyClass> >"?

It is worth reading more on templates, since some of the concepts involved are not trivial. The STL library already has linked lists, and it can handle most classes (as long as they have appropriate constructors and comparison operators).

If you have specific issues, perhaps you could provide code fragments so that others can suggest improvements and ways of dealing with errors.

Last edited by neonsignal; 09-10-2009 at 12:49 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked list C exvor Programming 14 06-22-2007 06:06 PM
Linked list manas_sem Programming 3 12-21-2006 01:53 AM
C linked list exvor Programming 4 04-28-2006 05:25 AM
linked list + c dilberim82 Programming 5 05-04-2005 11:48 PM
How to convert between list<T>::iterator and T* shreks Programming 2 08-26-2004 05:27 PM


All times are GMT -5. The time now is 04:51 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration