-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modifications to be compliant with deep copy of structures. #15
base: master
Are you sure you want to change the base?
Conversation
@@ -187,7 +192,7 @@ bool LinkedList<T>::add(int index, T _t){ | |||
} | |||
|
|||
template<typename T> | |||
bool LinkedList<T>::add(T _t){ | |||
bool LinkedList<T>::add(T& _t){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if it's a primitive (int, char, float...) type, and it gets by reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no problem at all. Show me an example that doesn't work.
ListNode<T> * x = rhs.root; | ||
// copy | ||
for(int i=0; i < rhs.size(); i++) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the pattern (Open bracket on the same line)
@@ -57,7 +58,7 @@ class LinkedList{ | |||
Adds a T object in the end of the LinkedList; | |||
Increment _size; | |||
*/ | |||
virtual bool add(T); | |||
virtual bool add(T&); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will cause incompatibility with major usage.. In the past, it was by reference, but was changed back to the Type in order to support pointers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pointers can be passed by reference. This is the safest method. Without that you are making copies of variables without sense. Trust on compiler :)
Nice! I had a few questions about the reference passing, can you please clarify it? |
@ivanseidel Sure. |
Linkedlists now supports deep copy using the copy constructors and the assignment operator that has been defined.