Jump to content
  • Advertisement
Sign in to follow this  
31337noob

problems with my linklist

This topic is 4812 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

here is the problem Type is a template so i can use anything like classes, structs,char.... here is the problem. c:\Documents and Settings\Administrator\Desktop\SoldatAdmin\linklist.h(25): error C2678: binary '==' : no operator found which takes a left-hand operand of type 'Scripts' (or there is no acceptable conversion) c:\Documents and Settings\Administrator\Desktop\SoldatAdmin\linklist.h(26): error C2664: 'Scripts::Scripts(const Scripts &)' : cannot convert parameter 1 from 'int' to 'const Scripts &' Reason: cannot convert from 'int' to 'const Scripts' No constructor could take the source type, or constructor overload resolution was ambiguous c:\Documents and Settings\Administrator\Desktop\SoldatAdmin\linklist.h(26): error C2553: no legal conversion of return value to return type 'Scripts' Type push_back(Type data) { //the errors point to here. if(data == NULL) return NULL; what do i do?

Share this post


Link to post
Share on other sites
Advertisement
Well the problem seems to be that you are trying to instantiate your linked list with a type that you can't compare to NULL. You'll need to change your logic since comparing types to NULL only makes sense for pointers.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Well the problem seems to be that you are trying to instantiate your linked list with a type that you can't compare to NULL. You'll need to change your logic since comparing types to NULL only makes sense for pointers.


then how can i make my linklist to accept structs and classes.

Share this post


Link to post
Share on other sites
If you pass by value like that then there is no invalid value you can test against, since every object must be valid (as an object that is, it could have an internal fail bit set, but you can't really deal with that). So don't test, just store the object. You could also specialise your member function for pointers to objects, and keep the test in that code, since pointers can be tested for nullness.

I'd recommend having a look at the implementation of std::list which came with your compiler. The names will be pretty wierd (lots of underscores that only library writers are allowed to use) but it will show you how to write a good linked list. Besides, once you've learnt how to write a linked list you'll be throwing it away in preference for std::list anyway, right?

Enigma

Share this post


Link to post
Share on other sites
my link list sortof works now.

the head of the linklist is always changing which is not suposed to do when there is new data. why would it be doing this?

Type *push_back(Type *data)
{
if(data == NULL)
return NULL;

if(head == NULL)
{
head = new Node(data);
//head->data = data;
tail = head;
cur = head;

}
else
{
tail->next = new Node(data);
//tail->next->data = data;
tail = tail->next;
cur = tail;
}

return tail->data;
}

what is wrong?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!