c++ - 'int' 之前的预期不合格 ID? Arduino库

标签 c++ arduino

<分区>

这可能是我错过的一些愚蠢的东西,但现在我一直收到这个错误:(。请帮忙!!这是我在 C++ 中的第一个库,所以我可能搞砸了语法。

此错误出现在这行代码中

  displayLED(int heightOfDisplay = 8, int widthOfDisplay = 32);

这是.h文件中的代码

#ifndef displayLED
#define displayLED
#include "Arduino.h"
#include <math.h>
#include <string.h>

class displayLED
{

private:

static const int heightOfDisplay;
static const int widthOfDisplay;
int verticalArray[8];
int horizontalArray[32];
int cursorPosition=0;
const int latchPin = 8;
const int clkPin = 7;
const int REDhorizontalSO = 6;
const int GREENhorizontalSO = 11;
const int BLUEhorizontalSO = 9;
const int verticalSO = 12;



public:

displayLED(int heightOfDisplay = 8, int widthOfDisplay = 32);
displayLED();
void constructWord(String   Word = "WELCOME");
void slideIn(String colorAnimator);
void fillArrays();
void pushToRegister(int sthToWrite1[], int sthToWrite2[], int sthToWrite3[],  int sthToWrite4[], int SOpin1, int SOpin2, int SOpin3, int SOpin4);
void shiftOutMultiple(uint8_t dataPin1, uint8_t dataPin2, uint8_t dataPin3, uint8_t dataPin4, uint8_t clockPin, uint8_t bitOrder, uint8_t val1, uint8_t val2, uint8_t val3, uint8_t val4)


};



#endif

这是我的 .cpp。为了简洁起见,我省略了其他功能。我希望它清楚。

#include "displayLED.h"


displayLED::displayLED(int heightOfDisplay, int widthOfDisplay) {
this->heightOfDisplay = heightOfDisplay;
this->widthOfDisplay = widthOfDisplay;
pinMode(latchPin , OUTPUT);
pinMode(clkPin , OUTPUT);
pinMode(REDhorizontalISO , OUTPUT);
pinMode(GREENhorizontalSO , OUTPUT);
pinMode(BLUEhorizontalSO , OUTPUT);
pinMode(vertcalISO , OUTPUT);
fillArrays();
}

displayLED::displayLED()    {
}


//this function fills all the array with zeros
void displayLED::fillArrays()   {
for(int j=0; j <= heightOfDisplay; j++) {
    verticalArray[j] = 0;
}

for(int j=0; j <= widthOfDisplay; j++)  {
    horizontalArray[j] = 1;
}
}

最佳答案

我认为您的 #define 守卫与您的类名冲突。预处理器将删除所有提及的 displayLed,这会产生非常奇怪的编译错误。

改变你的 guard 方式

#ifndef DISPLAYLED_H
#define DISPLAYLED_H

或者,您可以尝试使用#pragma once。现在大多数编译器都支持它。

关于c++ - 'int' 之前的预期不合格 ID? Arduino库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54512665/

相关文章:

java - 慢Arduino串口传输

android - 在 Android 应用程序中为蓝牙脉搏率传感器创建实时图表

c++ - 编写一个使用语音识别的程序......我应该从哪里开始?

matlab - Arduino 和 Matlab 之间的串行通信丢失数据

c++ - 为什么编译器在 vector 已满时不尝试分配连续内存(如果可能)?

c++ - Emacs 中的 CC 模式赋值缩进

c++ - cv::Mat 的序列化给出了奇怪的结果

c++ - 为我的 Visual Studio C++ 项目配置目标平台

c++ - C++串口发送数据和读取数据的方法

c++ - 简单的 constexpr - C26498 警告和 C2131 错误