0

I have a function 'transfer(int arr[12][7], char letter = 'a')' that is in another class with a header files that takes in 2 parameters. I am trying to set the letter as a default parameter, so I wouldn't have to pass it into the function every time I call it. This function is also in another class (Typeface.cpp) with a header file (Header.h), but when I declare this function, I receive the error: "C2065 'letter': undeclared identifier". Is this just not possible in C++?

Typeface.cpp:

#include "Header.h"
void Typeface::transfer(int arr[12][7], char letter = 'a') {
    ...
}

Header.h:

#pragma once
class Typeface {
   private:
      void transfer(int arr[12][7], char letter = 'a'); 
};
Kadia64
  • 1
  • 3
  • 1
    You only need to put the default parameter value where the function is declared. At the definition, just do `char letter`. – Nathan Pierson May 24 '22 at 04:13
  • The duplicate already answers what is wrong with your shown code, but the particular error message doesn't look like it would be generated by it. You should always provide a complete [mre] for any issue. – user17732522 May 24 '22 at 04:19
  • I reloaded Visual Studio 2022, and I have that exact same code, and it now says: "C2572 'Typeface::transfer': redefinition of default argument: parameter 1". – Kadia64 May 24 '22 at 04:23
  • Another approach (arguably less confusing) is to not provide that default argument, and write another overload: `void Typeface::transfer(int arr[12][7]) { transfer(arr, 'a');`. – Pete Becker May 24 '22 at 12:29

0 Answers0