应在"."之前使用主表达式令牌cpp



我只是从cpp开始,并尝试使用自定义结构。它看起来像这样:

typedef struct ws2811_t
{
uint64_t render_wait_time;                   //< time in µs before the next render can run
struct ws2811_device *device;                //< Private data for driver use
const rpi_hw_t *rpi_hw;                      //< RPI Hardware Information
uint32_t freq;                               //< Required output frequency
int dmanum;                                  //< DMA number _not_ already in use
ws2811_channel_t channel[RPI_PWM_CHANNELS];
} ws2811_t;

这就是我试图定义它的方式:

ws2811_channel_t ledstring = {
.gpionum = LED_PIN,
.invert = LED_INVERT,
.count = LED_COUNT,
.brightness = LED_BRIGHTNESS,
};
ws2811_t initString = {
.freq = LED_FREQ_HZ,
.dmanum = LED_DMA,
.channel[LED_CHANNEL] = ledstring,
};

但我得到错误:error: expected primary-expression before ‘.’ token .channel[LED_CHANNEL] = ledstring,

为什么?为什么其他变量运行良好,而只有那个变量会出错?

这里是批量和基本转录C->您的代码的C++。默认情况下,结构是所有公共的类。

struct ws2811_t{
uint64_t render_wait_time;                   //< time in µs before the next render can run
struct ws2811_device *device;                //< Private data for driver use
const rpi_hw_t *rpi_hw;                      //< RPI Hardware Information
uint32_t freq;                               //< Required output frequency
int dmanum;                                  //< DMA number _not_ already in use
ws2811_channel_t channel[RPI_PWM_CHANNELS];
};
ws2811_channel_t ledstring;
ledstring.gpionum = LED_PIN;
ledstring.invert = LED_INVERT;
ledstring.count = LED_COUNT;
ledstring.brightness = LED_BRIGHTNESS;
ws2811_t initString;
initString.freq = LED_FREQ_HZ;
initString.dmanum = LED_DMA;
initString.channel[LED_CHANNEL] = ledstring;

最新更新