P
P
PythonBeginner202019-01-13 02:25:55
C++ / C#
PythonBeginner20, 2019-01-13 02:25:55

Is there a difference where to put const for a method in c++?

Is there any difference between these two code options:

const int get_NOD() {
    return NOD;
  }

and this
int get_NOD() const{
    return NOD;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-01-13
@PythonBeginner20

There is a difference, and a big one:

const int get_NOD() {
    return NOD;
}

-- returns const int and may change *this
int get_NOD() const{
    return NOD;
}

-- returns an int and cannot change *this.
There is no difference between
const int get_NOD() {
    return NOD;
}

and
int const get_NOD() {
    return NOD;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question