Program don’t work correctly when object is changed to object pointer

Solution for Program don’t work correctly when object is changed to object pointer
is Given Below:

I use example of mDNSResolver library to resolve a local Host name to IP address as following :

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <mDNSResolver.h>

#define WIFI_AP         "myap"
#define WIFI_PASS       "mypass"
#define NAME_TO_RESOLVE "myhost.local"

using namespace mDNSResolver;

WiFiClient wifiClient;
WiFiUDP udp;
Resolver resolver(udp);

void setup() {
  Serial.begin(115200);
  int WiFiCounter = 0;
  // We start by connecting to a WiFi network
  Serial.println("Connecting to ");
  Serial.println(WIFI_AP);

  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_AP, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED && WiFiCounter < 30) {
    delay(1000);
    WiFiCounter++;
    Serial.print(".");
  }

  Serial.print("Resolving ");
  Serial.println(NAME_TO_RESOLVE);

  resolver.setLocalIP(WiFi.localIP());
  
  IPAddress ip = resolver.search(NAME_TO_RESOLVE);
  if(ip != INADDR_NONE) {
    Serial.print("Resolved: ");
    Serial.println(ip);
  } else {
    Serial.println("Not resolved");
  }
}

void loop() {
  // Required to clear the UDP buffer, as we can't unjoin a multicast group yet
  resolver.loop();
}

It work as i expect i.e the IP is resolved successfully and printed on serial console as :

Resolved: [RESOLVED IP ADDRESS, FOR EXAMPLE:] 192.168.1.33

But when i change resolver object to a pointer as following :

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <mDNSResolver.h>
#include <WiFiClient.h>

#define WIFI_AP "myap"
#define WIFI_PASS "mypass"
#define NAME_TO_RESOLVE "myhost.local"

using namespace mDNSResolver;

WiFiClient wifiClient;
WiFiUDP udp;
Resolver *resolver;

void setup()
{
  Serial.begin(115200);
  int WiFiCounter = 0;

  // We start by connecting to a WiFi network
  Serial.println("Connecting to ");
  Serial.println(WIFI_AP);

  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_AP, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED && WiFiCounter < 30)
  {
    delay(1000);
    WiFiCounter++;
    Serial.print(".");
  }

  resolver = new Resolver(udp);
  resolver->setLocalIP(WiFi.localIP());
  IPAddress ip = resolver->search(NAME_TO_RESOLVE);
  if (ip != INADDR_NONE)
  {
    Serial.print("Resolved: ");
    Serial.println(ip);
  }
  else
  {
    Serial.println("Not resolved");
  }

}

void loop()
{
  // Required to clear the UDP buffer, as we can't unjoin a multicast group yet
  resolver->loop();

}

The program can’t resolve any local host name anymore and following statement will print on serial console :

Not resolved

The if... else... statement in setup() function determine either IP is resolved successfully or no :

  if (ip != INADDR_NONE)
  {
    Serial.print("Resolved: ");
    Serial.println(ip);
  }
  else
  {
    Serial.println("Not resolved");
  }

Did i use object pointer correctly? If no, how must i fix that?

Call resolver = new Resolver(udp); before setup():

WiFiClient wifiClient;
WiFiUDP udp;
Resolver *resolver = new Resolver(udp);

Edit1:
For some reason, some boards must to be configured globally, and even if you pass a pointer to the object created it does not work. This is a behavior that is under discussion yet, as you can see in this post:
Class Instantiation only works globally but not in set up

So that is why I suggesting to declare and instantiate it globally.