Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anmaped
Copy link

@anmaped anmaped commented Oct 17, 2016

Linkedlists now supports deep copy using the copy constructors and the assignment operator that has been defined.

@@ -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){
Copy link
Owner

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?

Copy link
Author

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++)
{
Copy link
Owner

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&);
Copy link
Owner

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

Copy link
Author

@anmaped anmaped Oct 19, 2016

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 :)

@ivanseidel
Copy link
Owner

Nice! I had a few questions about the reference passing, can you please clarify it?

@anmaped
Copy link
Author

anmaped commented Oct 19, 2016

@ivanseidel Sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants