The String object created as return from IPAddress.toString() as parameter to constructor of NtpClient is temporary. It contains the char array returned by c_str(). NTPClient doesn't copy the string, only stores a reference to it. And the referenced string (char array) doesn't exist at the time the NTPClient wants to use it.
class TestClass {
public:
TestClass(const char* _ip) : ip(_ip) { }
void test() {
Serial.println("--");
Serial.println(ip);
Serial.println("--");
}
private:
const char* ip;
};
//String s("abc");
//TestClass Test(s.c_str()); <- this works
TestClass Test(String("abc").c_str()); // <- this cant'tcan't work
void setup() {
Serial.begin(9600);
Test.test();
}