Compilation error: conversion from 'int' to 'String' is ambiguous

Hi.
I am using Seeeduino Xiao with String variable (inStr) initialized by NULL. However I got a compilation error.

C:\Projects\Payload simulator\Codes\Arduino\pcg_01\pcg_01.ino: In member function 'void Serialport::readLine()':
C:\Projects\Payload simulator\Codes\Arduino\pcg_01\pcg_01.ino:151:18: error: conversion from 'int' to 'String' is ambiguous
   String inStr = NULL;
                  ^
In file included from C:\Users\tonyz\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\cores\arduino/Arduino.h:80:0,
                 from C:\Users\tonyz\AppData\Local\arduino\sketches\73B329A8803FC33FB337E6F86C4CDBFD\sketch\pcg_01.ino.cpp:1:
C:\Users\tonyz\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\cores\arduino/WString.h:61:2: note: candidate: String::String(const __FlashStringHelper*)
  String(const __FlashStringHelper *str);
  ^~~~~~
C:\Users\tonyz\AppData\Local\Arduino15\packages\Seeeduino\hardware\samd\1.8.5\cores\arduino/WString.h:59:2: note: candidate: String::String(const char*)
  String(const char *cstr = "");
  ^~~~~~
exit status 1

Compilation error: conversion from 'int' to 'String' is ambiguous

I assume that assigning NULL to a String variable is acceptable, but not very sure. below are my code.

class Serialport {  
  public:
    char inBuffer[64] = {0};   
    char outBuffer[64] = {0};  
    bool inputFlag;  
    bool outputFlag;  
    char inChar;       
    String inStr;    
    Serialport() {    // class constructor
      inBuffer[0] = '\0';
      outBuffer[0] = '\0';
      inputFlag = false; 
      outputFlag = false; 
      inChar= NULL;
      inStr = NULL;
    }
    char readChar();
    void readLine(); 
    void sendLine();
};


char Serialport::readChar() {   //function to read a char in the placeholder and return it if sucessfully read, or return '0x0'
  char inChar = NULL;
  if (Serial.available() > 0) {
    inChar = Serial.read();
    return inChar;
  }
  return inChar;
}

void Serialport::readLine() {  //function to read a line ended with '\n' into inBuffer and set the flag if sucssfully read.
  inStr = NULL;
  if (Serial.available()>0) {
    inStr = Serial.readStringUntil(EOL);  // this is blocking read.
  }
}

the compilation indicates both lines of "inStr = NULL" have error.

any help is greatly appreciated, Thanks.

Don't assume :wink:

Why would you make it NULL? If you want it to be empty, you can use String inStr = "".
Or in your readLine() method leave inStr = NULL; out.

the reason to assign it to NULL is after readLine call, I can easily use if statement to check if (ser.inStr == NULL) ....and I saw others doing so.
In readLine() method, I must have "inStr=NULL" to flush previously received line.
So, is "String inStr=NULL" illegal? this is key question of the post.

Also from error message, it seems compiler takes NULL as int and trying to convert int to String...however, my impression is NULL=='\0'. I have checked corresponding WString.cpp file, and find below constructor as one of many constructors:

String::String(char c)
{
	init();
	char buf[2];
	buf[0] = c;
	buf[1] = 0;
	*this = buf;
}

if the compiler recognized NULL=='\0', it should be no problem.

They're different. NULL is an int of value zero. It has a special name because it's nearly always used with pointers (its preferred replacement in Modern C++ is nullptr which is actually a pointer type, not an int). You can't assign an int type to a String.

\0 is type char with a value of zero. You can assign that to a String. So, you could to any of:

   inStr = "";
   inStr = "\0";
   inStr = '\0';

The first of these makes your intentions the clearest, so use that.

@gfvalvo. Thank you so much for the explanation.
I also found a post which provides further details.