【发布时间】:2014-08-31 10:55:25
【问题描述】:
我正在使用 TinyXML2 开发一个项目。我正在尝试调用方法 XMLAttribute* FindAttribute(const char* name)
该方法由实现定义为:
public :
const XMLAttribute* FindAttribute( const char* name ) const;
private :
XMLAttribute* FindAttribute( const char* name );
我有点困惑,一个方法如何在公共和私有范围内具有相同的签名。我只能猜测它没有,尽管我并不真正理解公共定义末尾的 const 部分。但是,我需要调用公共方法,但 g++ sais "tinyxml2::XMLElement::FindAttribute(const char*) 是私有的"
如何调用public方法,方法原型末尾的const部分有什么作用?
【问题讨论】:
-
是的,这与尾随的
const有关,而不是public/private。如果您想象传递给这些函数的隐式this*,它就像两个函数foo(T *this)和foo(T const *this)。