这个const之前的方法名是什么意思? [英] What this const before method name mean?
本文介绍了这个const之前的方法名是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我们的一本教科书中,我们建议我们应该使用C ++中的接口作为一个好的设计实践。它们给出以下示例:
In one of our text-books it is suggested that we should use interfaces in C++ as a good design practice. They give below example;
class IAnimation
{
public:
virtual void VAdvance(const int deltaMilisec) = 0;
virtual bool const VAtEnd() const = 0;
virtual int const VGetPostition() const = 0;
};
我没有意义:
virtual bool const VAtEnd() const = 0;
virtual int const VGetPostition() const = 0;
我知道const用于after(),使它们可以从const实例调用。但是VAtEnd和VGetPosition(方法名称)之前的const是什么意思?
I know const is used after () to make them invocable from const instances. But what const before VAtEnd and VGetPosition (method names) mean?
谢谢。
推荐答案
这意味着返回类型是const,它是相同的:
It means the return type is const, it's the same as:
virtual const bool VAtEnd() const = 0;
virtual const int VGetPostition() const = 0;
它没有实际意义,因为返回值被复制。
It has no practical meaning though, as the return value is copied anyway.
如果你要返回一个对象:
If you'd be returning an object though:
struct A
{
void goo() {}
};
const A foo() {return A();}
int main()
{
A x = foo();
x.goo(); //ok
foo().goo(); //error
}
这篇关于这个const之前的方法名是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文