undefined reference to `CDebug::logFileFoundError(char const*)'

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
  }

CString.cpp (20 KB)

CString.h (8.25 KB)

Debug.cpp (18.4 KB)

Debug.h (4.58 KB)

WifiManager.cpp (26.6 KB)

WifiManager.h (4.41 KB)

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.

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.

 void logFileFoundError(const char* strFileName)
  {

You forgot the class name:

void CDebug::logFileFoundError(const char* strFileName)
  {

oqibidipo:

 void logFileFoundError(const char* strFileName)

{




You forgot the class name:


void CDebug::logFileFoundError(const char* strFileName)
  {

DOOOOOH - what a waste of time. Too focused on the data 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:

char const * pointerToConstantContent1;
const char * pointerToConstantContent2;

OK. So the operator's return type, and the function's argument type should be char const * const.

There really do need to be two consts, since you don't want the user changing where the pointer points or what the pointer points to.

PaulS:
OK. So the operator's return type, and the function's argument type should be char const * const.

There really do need to be two consts, since you don't want the user changing where the pointer points or what the pointer points to.

OK done. Thanks.