[問題] private的使用方式
看板C_and_CPP (C/C++)作者sstrange (Q^_________^Q)時間4年前 (2020/12/01 09:58)推噓1(1推 0噓 15→)留言16則, 5人參與討論串1/1
開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC Mbed for ARM Cortex-M4
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
最近在學習Mbed OS的開發,看了很多官網的sample code,因為之前都使用C沒使用過C++
在看到serial的driver時,sample code的main function直接使用private member?
以前的觀念是private只能被自己的member使用,外部無法直接存取
https://os.mbed.com/docs/mbed-os/v6.3/apis/unbufferedserial.html
裡面的sample
serial_port.baud(9600);
baud是private member卻可以在main裡面直接使用,這樣是正確的嗎?
餵入的資料(Input):
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
程式碼(Code):(請善用置底文網頁, 記得排版,禁止使用圖檔)
class SerialBase : private NonCopyable<SerialBase> {
public:
void baud(int baudrate);
....
}
int main(void)
{
// Set desired properties (9600-8-N-1).
serial_port.baud(9600);
serial_port.format(
/* bits */ 8,
/* parity */ SerialBase::None,
/* stop bit */ 1
);
// Register a callback to process a Rx (receive) interrupt.
serial_port.attach(&on_rx_interrupt, SerialBase::RxIrq);
}
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.201.89.41 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1606787936.A.B95.html
→
12/01 10:08,
4年前
, 1F
12/01 10:08, 1F
→
12/01 10:09,
4年前
, 2F
12/01 10:09, 2F
→
12/01 10:24,
4年前
, 3F
12/01 10:24, 3F
→
12/01 10:24,
4年前
, 4F
12/01 10:24, 4F
→
12/01 10:24,
4年前
, 5F
12/01 10:24, 5F
→
12/01 10:24,
4年前
, 6F
12/01 10:24, 6F
→
12/01 10:24,
4年前
, 7F
12/01 10:24, 7F
→
12/01 10:24,
4年前
, 8F
12/01 10:24, 8F
→
12/01 10:24,
4年前
, 9F
12/01 10:24, 9F
→
12/01 10:24,
4年前
, 10F
12/01 10:24, 10F
→
12/01 11:18,
4年前
, 11F
12/01 11:18, 11F
推
12/02 20:02,
4年前
, 12F
12/02 20:02, 12F
→
12/02 20:02,
4年前
, 13F
12/02 20:02, 13F
→
12/02 20:02,
4年前
, 14F
12/02 20:02, 14F
→
12/02 20:02,
4年前
, 15F
12/02 20:02, 15F
→
12/02 20:02,
4年前
, 16F
12/02 20:02, 16F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章