开发者

What does const denote here?

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

template <class T> class MaximumPQ { 
public:
virtual ~MaximumPQ () {}

virtual bool IsEmpty () const = 0;    

virtual voi开发者_如何学运维d Push(const T&) = 0;

virtual void Pop () = 0;
};


The first one informs 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.

Basically, it guarantees that the method is side-effect free.

The second one specifies that the object referred to by the passed reference will not be modified - that only const methods on it will be called.

There are no equivalent signatures in C#.


IsEmpty() is a const-qualified member function. It means that the this pointer is const-qualified, so it will have a type of const MaxPQ*. Code inside of IsEmpty() cannot call any member functions on this that are not themselves const-qualified, nor can it modify any data members that are not mutable.

To the best of my knowledge, there is nothing similar in C#.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜