試圖瞭解Arduino IDE的SDFat庫的功能。我偶然發現了SDfat.h頭文件中的這些代碼行。瞭解C++中的類聲明
/**
1* \class SdBaseFile
2* \brief Class for backward compatibility.
3*/
4 class SdBaseFile : public FatFile {
5 public:
6 SdBaseFile() {}
7 /** Create a file object and open it in the current working directory.
8 *
9 * \param[in] path A path for a file to be opened.
10 *
11 * \param[in] oflag Values for \a oflag are constructed by a
12 * bitwise-inclusive OR of open flags. see
13 * FatFile::open(FatFile*, const char*, uint8_t).
14 */
15 SdBaseFile(const char* path, uint8_t oflag) : FatFile(path, oflag) {}
16 };
如果有人能請解釋一下我這個類的聲明是如何工作的。
1)第#4行中的:public Fatfile
是做什麼的。
2)爲什麼第6行和第15行有兩個構造函數(如果是這樣的話)。
我的理解受到這裏定義/聲明缺乏語法理解的限制。感謝幫助。
感謝
1.它表示該類是從另一個名爲FatFile的類派生的。 2.這個類可以用兩種方式實例化,所以有兩個構造函數。我建議你閱讀一本關於C++的好書 –
任何C++教程/書都會詳細回答這些問題。 1)繼承。 2)是的,它們是構造函數,第一個是默認構造函數,另一個是構造函數,它接受輸入來打開文件 –
閱讀繼承和函數重載。有關圖書推薦,請參閱[這裏](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)。 –