C++;初学者:在'之前应为不合格id;int'; 正如你从这个问题中猜到的,我对用C++进行OOP编程是很新的。(我以前只学过Java) 无论如何,我正在尝试为Arduino项目创建一个自定义类,并得到提到的错误。这是我的档案:

C++;初学者:在'之前应为不合格id;int'; 正如你从这个问题中猜到的,我对用C++进行OOP编程是很新的。(我以前只学过Java) 无论如何,我正在尝试为Arduino项目创建一个自定义类,并得到提到的错误。这是我的档案:,c++,oop,arduino,C++,Oop,Arduino,标题可触摸 #ifndef Touchable #define Touchable #include <Adafruit_TFTLCD.h> #include <Arduino.h> class Touchable { public: int posX; int posY; Touchable(int, int); //<-- Error here ~Touchable(); void Touchable::draw(

标题可触摸

#ifndef Touchable
#define Touchable
#include <Adafruit_TFTLCD.h>

#include <Arduino.h>

class Touchable {
  public:
    int posX;
    int posY;
    Touchable(int, int); //<-- Error here
    ~Touchable();
    void Touchable::draw();
};

#endif
\ifndef可触摸
#定义可触摸的
#包括
#包括
类可触摸{
公众:
int-posX;
int-posY;

Touchable(int,int);//您必须为include-guard宏选择一个不同的名称(通常是
Touchable\u H
),因为预处理器将
Touchable.H
中的代码转换为:

class {
public:
   int posX;
   int posY;
   (int, int);
   ~();
   void ::draw();
};

所有
#包含
此文件的文件也是如此……或者您可以使用。

如果您在头文件中输入int x和int y,它是否编译?我看到的唯一问题是Touchable::draw()中的额外限定(删除Touchable::).Nope,相同的错误请提供编译器给出的确切错误。@PedroBoechat仍然是相同的问题很好的捕获。这就是为什么有规则在宏中使用所有大写字母,而不是在代码中使用它们。该死,我不会猜测很久了:D这么简单的想法例如:#ifndef#u Touchable#define#u Touchable?@user7408924通常最好使用所有大写字母宏的大写字母so
#如果ndef TOUCHABLE_H
#定义TOUCHABLE_H
@user7408924。
In file included from sketch/Touchable.cpp:1:0:
Touchable.h:11: error: expected unqualified-id before 'int'
     Touchable(int x, int y);
               ^
Touchable.h:11: error: expected ')' before 'int'
Touchable.h:12: error: expected class-name before '(' token
     ~Touchable();
               ^
Touchable.h:13: error: invalid use of '::'
     void Touchable::draw();
                          ^
Touchable.h:14: error: abstract declarator '<anonymous class>' used as declaration
 };
 ^
Touchable.cpp:5: error: expected id-expression before '(' token
 Touchable::Touchable(int x, int y) {
                     ^
Touchable.cpp:10: error: expected id-expression before '~' token
 Touchable::~Touchable() {
            ^
exit status 1
expected unqualified-id before 'int'
class {
public:
   int posX;
   int posY;
   (int, int);
   ~();
   void ::draw();
};