在Arduino中创建库时出现预期的unqualified-id错误

时间:2019-03-06 01:27:29

标签: arduino

我正在尝试在Arduino上创建自己的库,同时还使用其他库。但是我的头文件的第12行出现了这个错误:

  

在')'令牌之前需要不合格ID

主文件:

#include "firealarm.h" 
void setup() {
  firealarm.begin;
}

void loop() {
  firealarm.gas_values();
}

头文件:

#include <MQ2.h>

#ifndef firealarm
#define firealarm

#if ARDUINO >= 100
#include "Arduino.h"
#endif

class firealarm {
  public:
    firealarm(); //this is where it says the error occurs
    void begin (int baudRate = 9600);
    gas_values()
  private:
    MQ2 mq2(A0);

    int lpg, co, smoke;

};
#endif

Cpp文件:

#include "firealarm.h"

firealarm::firealarm() :
{
}
void firealarm::begin(int baudrate)
{
    Serial.begin(baudrate);
    Serial.println("Firealarm libary created successfully")
        mq2.begin;
}
void firealarm::gas_values()
{
    float *values = mq2.read(true);
    lpg = mq2.readLPG();
    co = mq2.readCO();
    smoke = mq2.readSmoke();
}

我还计划在其中包含其他库。但是我无法让它只与它一起工作。

1 个答案:

答案 0 :(得分:0)

在其他问题中,您<html> <head> <title></title> <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script> </head> <body> <script type="text/javascript"> var hostweburl; // Load the required SharePoint libraries. // Get the URI decoded URLs. hostweburl = "http://sp:12001"; var scriptbase = hostweburl + "/_layouts/15/"; // Load the js files and continue to // the execOperation function. //$.getScript(scriptbase + "init.js"); //$.getScript(scriptbase + "MicrosoftAjax.js"); //$.getScript(scriptbase + "sp.core.js"); //$.getScript(scriptbase + "sp.runtime.js"); //$.getScript(scriptbase + "sp.js"); $(document).ready(function () { //ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js"); $.getScript(scriptbase + 'init.js', function () { $.getScript(scriptbase + 'MicrosoftAjax.js', function () { $.getScript(scriptbase + 'sp.core.js', function () { $.getScript(scriptbase + 'SP.Runtime.js', function () { $.getScript(scriptbase + 'SP.js', function () { retrieveListItems("http://sp:12001") }) }); }); }); }); }); // Continue your program flow here. function retrieveListItems(siteUrl) { var clientContext = new SP.ClientContext(siteUrl); var oList = clientContext.get_web().get_lists().getByTitle('MyList2'); var camlQuery = new SP.CamlQuery(); camlQuery.set_viewXml( '<View><Query><Where><Geq><FieldRef Name=\'ID\'/>' + '<Value Type=\'Number\'>1</Value></Geq></Where></Query>' + '<RowLimit>10</RowLimit></View>' ); this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync( Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed) ); } function onQuerySucceeded(sender, args) { var listItemInfo = ''; var listItemEnumerator = collListItem.getEnumerator(); while (listItemEnumerator.moveNext()) { var oListItem = listItemEnumerator.get_current(); listItemInfo += '\nID: ' + oListItem.get_id() + '\nTitle: ' + oListItem.get_item('Title'); //'\nBody: ' + oListItem.get_item('Body'); } alert(listItemInfo.toString()); } function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); } </script> </body> </html> 位于#define firealarm顶部附近,这意味着,一旦firealarm.h一词在文件中的后面出现,它就会被完全删除。因此对于编译器,您的文件如下所示:

firealarm

这不是有效的C ++,因此编译器会引发错误。文件稍后会出现更多错误,例如函数class { public: (); // ..... more code 的声明,该函数没有返回类型,并且在行末没有分号。

将包含保护(gas_values#ifdef行重命名为您不使用的单词,例如#define,或替换它们(以及__firealarm_h_included行) )和一个#endif

相关问题