I don't understand why I am getting this compile error.
Can't anyone enlighten me.
I have defined these the function is debug.cpp as follows but calls to the function ' debug.logFileOpenError(strFilename.c_str()) are still causing this unresolved external error.
It must be a data type mismatch with the parameters but I don't know how to fix it.
I tried versions of these functions with 'char strFilename[]' as the parameter but that doesn't work.
void logFileFoundError(const char* strFileName)
{
#ifdef DEBUG
Serial.print(F("File '"));
Serial.print(strFileName);
Serial.println(F("' was not found!"));
#elif defined DIAGNOSTIC
serialHC05.print(F("File '"));
serialHC05.print(strFileName);
serialHC05.print(F("' was not found!"));
serialHC05.print("\r\n");
#endif
}
void logFileFoundError(const __FlashStringHelper* strFileName)
{
#ifdef DEBUG
Serial.print(F("File '"));
Serial.print(strFileName);
Serial.println(F("' was not found!"));
#elif defined DIAGNOSTIC
serialHC05.print(F("File '"));
serialHC05.print(strFileName);
serialHC05.print(F("' was not found!"));
serialHC05.print("\r\n");
#endif
}
void logFileOpenError(const char* strFileName)
{
#ifdef DEBUG
Serial.print(F("File '"));
Serial.print(strFileName);
Serial.println(F("' could not be opened!"));
#elif defined DIAGNOSTIC
serialHC05.print(F("File '"));
serialHC05.print(strFileName);
serialHC05.print(F("' could not be opened!"));
serialHC05.print("\r\n");
#endif
}
void logFileOpenError(const __FlashStringHelper* strFileName)
{
#ifdef DEBUG
Serial.print(F("File '"));
Serial.print(strFileName);
Serial.println(F("' could not be opened!"));
#elif defined DIAGNOSTIC
serialHC05.print(F("File '"));
serialHC05.print(strFileName);
serialHC05.print(F("' could not be opened!"));
serialHC05.print("\r\n");
#endif
}
PaulS:
Look at the error message. Look at the relative positions of char, const, and *.
Look at the function declaration (and implementation). Are the relative positions the same?
There IS a difference between a const pointer to data and a pointer to const data.
I did notice that but I still don't understand how to resolve it.
In the functions where my call to logFileOpneError(...) etc I have not declared any local variables as const.
CString strFilename; contains a char array (char m_strBuff[...]) and I have the following operator function in my CString class.
operator const char*(){ return m_strBuff;}
I tried making a char cons* version of my functions and that doesn't work either.
So what else is left and how do I fix it? I am at a loss.
In the functions where my call to logFileOpneError(...) etc I have not declared any local variables as const.
In you declaration of the () operator, what, exactly, should be const(ant)? Should the user be able to make the pointer point somewhere else? If not, the pointer should be const (char const *()).
Should the user be able to change the data that the pointer points to? If not, the data should be const (const char *()).
If the user should not be able to make the pointer point somewhere else, and should not be able to change the data pointed to, both need to be const (const char const *()).
The signature of your method needs to match the type of the argument, or be more restrictive. I'd use const char const * as the type.
PaulS:
In you declaration of the () operator, what, exactly, should be const(ant)? Should the user be able to make the pointer point somewhere else? If not, the pointer should be const (char const *()).
Should the user be able to change the data that the pointer points to? If not, the data should be const (const char *()).
If the user should not be able to make the pointer point somewhere else, and should not be able to change the data pointed to, both need to be const (const char const *()).
The signature of your method needs to match the type of the argument, or be more restrictive. I'd use const char const * as the type.
I just read that const char* and char const* mean the same thing but that the former is more intuitive.
Actually, according to the standard, const modifies the element directly to its left. The use of const at the beginning of a declaration is just a convenient mental shortcut. So the following two statements are equivalent: