[英]What is this variable in a c++ class that is aligned with the access specifiers? [closed]
我正在學習 C++,我正在為 arduino 上的 LED 創建 class。 我正在關注的教程中的示例 class具有標准訪問說明符public
和private
,但它也有第三個我不理解的bool TYPE
。
我了解 TYPE 用於支持兩種類型的 LED。 我不明白為什么TYPE
不是 RGBLed class 中的私有或公共變量? . 還有為什么是大寫? (約定規定私有變量應該小寫不?)這是一個錯字,還是這是一種設計模式?
我最好的猜測是,這是某種宏或全局變量。
#ifndef RGBLED_H
#define RGBLED_H
#define COMMON_ANODE 0
#define COMMON_CATHODE 1
class RGBLed
{
public:
RGBLed(int redPin, int greenPin, int bluePin, bool type = COMMON_ANODE);
void setRGB(int R, int G, int B);
void turnOff();
private:
const int rPin,gPin,bPin;
bool TYPE; // <---------- what is this line?
};
#endif //__RGBLED_H
#include "RGBLed.h"
#include <Arduino.h>
/**
* RGBLed constructor.<BR>
* redPin, greenPin, bluePin - three PWM pin on arduino board.
*/
RGBLed::RGBLed(int redPin, int greenPin, int bluePin, bool type) : rPin(redPin), gPin(greenPin), bPin(bluePin)
{
TYPE = type; // <---------- is this a linting erorr? or does this need to be indented?
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.