c++: 'WiFiClient' 没有命名类型

c++: 'WiFiClient' does not name a type

这是一些简单的 C++ 源代码:https://github.com/kenpeter/test_cpp_lib

我在 arduino 中编译了它,我得到了“'WiFiClient' 没有命名类型”。基本上我想做的是在 run_mode.cpp 中定义一个变量 "client",然后我想在 mqtt.cpp.

中使用它

test_cpp_lib.ino

#include <WiFiClient.h>;
#include "run_mode.h";
#include "mqtt.h";

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println("test");
  delay(2000);
}

mqtt.cpp

extern WiFiClient client;

// do something with client

run_mode.cpp

WiFiClient client;

run_mode.h

extern WiFiClient client;

mqtt.h 为空。

WiFiClient 不是像 int 或 char 这样的内置类型。它是一个 class ,必须先定义(通常在头文件中),然后才能创建它的实例。在您的示例代码中,没有这样的定义,但您正试图在 run_mode.cpp 中实例化 WiFiClient。也许 run_mode.cpp 必须包括 WiFiClient.h.

顺便说一句,您不得在#include 指令的末尾添加分号。