What does const mean here?

What does const mean in the following C ++ code? What is equivalent to this in C #? I am C # code and I am trying to learn C ++.

template <class T> class MaximumPQ { public: virtual ~MaximumPQ () {} virtual bool IsEmpty () const = 0; virtual void Push(const T&) = 0; virtual void Pop () = 0; }; 
+4
source share
2 answers

The first tells the compiler that the method will not change any member variables of the object it is called on, and will also only make calls to other const methods.

In principle, it ensures that the method is free from side effects.

The second indicates that the object referenced by the link will not be changed - only the const method on it will be called.

There are no equivalent signatures in C #.

+9
source

IsEmpty() is a constant member function. This means that the this pointer has const qualification, so it will be of type const MaxPQ* . The code inside IsEmpty() cannot call any member functions on this that are not constant in themselves, nor can they change any data elements that are not mutable .

As far as I know, there is nothing like that in C #.

+6
source

All Articles