Saturday, October 10, 2020

Error C2664 'Employee::Employee(const Employee &)': cannot convert argument 1 from 'const char [4]' to 'char *'

used function_name(char*,char*) to define strings. later on in main(), assign them with literals such as "Bob", "Robert" , then get this error.

Error C2664 'Employee::Employee(const Employee &)': cannot convert argument 1 from 'const char [4]' to 'char *'

  1. C++ cannot convert parameter 1 from 'const char *' to 'char *'
  2. Cannot convert argument 1 from 'const wchar_t [16]' to 'LPTSTR'
  3. error C2664 cannot convert argument 1 from 'const char [11]' to 'LPSTR'
  4. You have some options:

    1. Disable Conformance Mode (easiest) : tested
    2. Cast to a char* : tested
    3. Define as non const: ?
    4. Make function take const arguments : tested such as const char*...

  5. Compiler Error C2664
  6. it has many good examples and need to browse when got time...

    If a temporary object is passed to a function that takes a reference to an object as a parameter, that reference must be a const reference.

    If the function is passed a parameter that is not of the type that the function expects, a temporary object is created by using the appropriate constructor. This temporary object is then passed to the function. In this case, the temporary object is used to initialize the reference. In earlier versions of the language, all references could be initialized by temporary objects.

    To fix C2664, 1. Recheck the prototype for the given function and correct the argument noted in the error message. 2. Supply an explicit conversion if necessary.

No comments:

Post a Comment