[英]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.