Why won't C++ allow non-const to const conversion in copy ctor?

c++, constants, copy-constructor

Solution

You're not trying to do a non-const to const conversion. You're attempting to call two methods which are not const an a const reference (calls to prev and value). This type of operation is strictly forbidden by const semantics.

What you could do instead is use the fields prev_ and value_ directly. Because it's a member of the same type you can access privates which will be available on the const object.

Problem

I have two getter members: ``` Node* prev() { return prev_; } int value() { return value_ } ``` Please note the lack of const identifiers (I forgot them, but now I want to know why this won't work). I am trying to get this to compile: ``` Node(Node const& other) : prev_(other.prev()), value_(other.value()) { } ``` The compiler rejects this. I thought that C++ allows non-const to const conversion in function parameters, such as: ``` { Foo(int bar); } Foo(const int bar) { //lala } ``` Why won't it let me do the same thing with a copy constructor? The const identifier means I promise not to change anything, so why would it matter if I get my value from a const or non-const source?

Original source