will this be a problem? :(
Yeah but you can solve it ;)
The variable you modify is allowed to be modified in a const Method, right?
Then make the variable mutable! :D
1 2 3 4 5 6 7 8 9 10
|
class A
{
public:
A() {_value = 5; }
void changeValue() const { _value = 10; }
void getValue() const { return _value; }
private:
mutable int _value;
};
|
With that knowledge, make all Methods const that won't make any changes that are visible from outside.
const correctness is very important ;)
And since this might be the source of the problem, I think you understand what i mean ^^
The other way to solve the might-be problem might be changing the constructor to this, but it is not recommended since it copies the whole value (which might be a gigantic object!).
Tree(Tree<T> other); // -> pass by value
edit: back to the problem
So, i think you create the object in this line:
FirstElement=new ListNode<T>(Value2Assign);
or in one of those
ListNode<T> *NewElement=new ListNode<T>(Value2Assign);
I guess you ListNode Constructor looks something like this
ListNode(const T& value) : _value(value) { /*stuff*/ }
and not like this:
ListNode(T value) : _value(value) { /*stuff*/ }
So, here the problem comes.
You give ListNode a
const T reference, (value is const and must not be changed!)
Now you call the constructor of Tree<T> where you pass a
const T&
since you have
no constructor that takes a const T& it searches for a constructor that takes
the parameter by value, you haven't got that either.
So, your compiler knows that this is a
const T& and in your Tree you just provide the implementation with
T& as parameter, which
might modify value and therefore is not an option
because the value is const.
Note: all this is under the assumption that the ListNode takes a const T&
if it takes the parameter by value the problem is something else