Is this class declaration wrong? " Declaration has no storage class or type specifier" error While trying to setup  an ESP32 as mqtt publisher I am getting strange errors. Here is my code:
#include &quot;mqttSetup.h&quot;
#include &lt;WiFi.h&gt;
#include &lt;PubSubClient.h&gt;

static byte httpFailCounter = 0;
byte counter = 0;

const char *ssid = &quot;SSID&quot;;
// const char *password = &quot;xxxxx&quot;;
const char *passphrase = &quot;xxxxx&quot;;

WiFiClient espClient;

const char *mqtt_server = &quot;192.168.1.39&quot;;
const int mqttPort = 1883;
const char *mqttUser = &quot;xxxx&quot;;
const char *mqttPassword = &quot;xxxxx&quot;;

PubSubClient pubClient(espClient);

pubClient.setServer(mqtt_server, mqttPort); 

void checkConnection()
{
    if (WiFi.status() == WL_CONNECTED)
    {
        counter = 0; //reset counter
    }
    else if (WiFi.status() != WL_CONNECTED)
    {
        WiFi.begin(ssid, passphrase);
    }
    while (WiFi.status() != WL_CONNECTED)
    {
        delay(500);
        Serial.print(&quot;.&quot;);

        counter++;
        if (counter &gt;= 60)
        {
            ESP.restart();
        }
    }
}

void reconnect()
{
 
    while (!pubClient.connected())
    {
        Serial.print(&quot;Attempting MQTT connection...&quot;);
        // Create a random client ID
        const char *clientID = &quot;ESP32D-MQTT&quot;;
        // Attempt to connect
        if (pubClient.connect(clientID))
        {
            Serial.println(&quot;connected&quot;);
            // Once connected, publish an announcement...
            pubClient.publish(&quot;outTopic&quot;, &quot;Hello from ESP&quot;);
            // ... and resubscribe
            //   client.subscribe(&quot;inTopic&quot;);
        }
        else
        {
            Serial.print(&quot;failed, rc=&quot;);
            Serial.print(pubClient.state());
            Serial.println(&quot; try again in 5 seconds&quot;);
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}

I don't understand why the compiler is spitting out the following two errors:
this declaration has no storage class or type specifier (referring to my pubClient declaration)

expected a ';'

It doesn't have any issue when I declare the pubClient but at the line :
pubClient.setServer(mqtt_server, mqttPort);
where I use the pubClient it gives the error.
Besides I don't see any ; missing in the code.
Could you please help me figure out the source of error?

Header file for this code chunk
#ifndef MQTTSETUP_H
#define MQTTSETUP_H



void checkConnection();
void reconnect();


#endif

------------ Main sketch---------
#include &lt;Arduino.h&gt;
#include &quot;Wire.h&quot;
#include &quot;tempSensor.h&quot;
#include &quot;mqttSetup.h&quot;




void setup()
{
  Wire.begin();

  Serial.begin(115200);
  while (!Serial)
    ;

  shtBegin();
  checkConnection();
}

void loop()
{
  uint32_t newTime = millis();
  static uint32_t oldTime = 0;
  static uint32_t t2 = 0;

  float temp = 0.0;
  float humid = 0.0;

  char senVals[50];

  if (newTime - oldTime &gt;= 10000)
  {
    oldTime = newTime;

    readsht(temp, humid);
    snprintf(senVals, 50, &quot;Temp: %.2f Humid: %.2f&quot;, temp, humid);
    Serial.println(senVals);

  }
}
Code goes in functions, not the global scope.
Your line
pubClient.setServer(mqtt_server, mqttPort);

should be inside a function. Most probably setup() so it gets called when your program starts.
Incidentally - where are setup() and loop() - the two functions that are required by Arduino code?