在我的.cpp程序的.h文件中,我有以下內容。
FILE *sequence_file_pointer_; //holds the FILE pointer to the file itself
然後我告訴eclipse生成getter和setter,我得到了這個有趣的結果。
const FILE*& getSequenceFilePointer() const;
我想我知道指針地址和常量的所有信息之後,我就看到它們給了我這個。我理解左邊的常量,它會返回一個常量文件指針,但我不明白右邊的常數以及FILE*
和getSequenceFilePointer()
之間的和號。任何幫助?const FILE *&getSequenceFilePointer()const; ECLIPSE
class Configuration {
public:
const FILE*& getSequenceFilePointer() const;
private:
FILE *sequence_file_pointer_; //holds the FILE pointer to the file itself
}
右邊的const使它成爲一個「const成員函數」。該符號稱爲「參考」。在這種情況下,您可以將返回類型更改爲「FILE *'或」const FILE *' – 2014-09-22 19:20:32
請參閱http://stackoverflow.com/questions/751681/meaning-of-const-last-in-ac-method-後綴「const」的聲明。 – juanchopanza 2014-09-22 19:20:49
你正在使用的工具是getter/setter生成工具,實質上是模板化的腦死亡。它只需要成員變量的類型('FILE *'),然後生成一個const-「getter」,它返回所述變量的const-reference-to-type類型。這是否適合您的需求取決於您(如果是這樣,我會發現它很奇怪,因爲它本質上爲您提供了對「FILE *」的引用,您實際上無法使用它)。 – WhozCraig 2014-09-22 19:43:15