0

I'm getting this error: "no instance of constructor matches the argument list" I don't get what am I doing wrong? why can't it convert the "someone" const char[8] to char* (as it is in the constructor) I'd love to get some help, thank you so much!
Constructor:

Student::Student(long id, char* name) {
   ...
}

Main:

Student s1(123456789, "someone");
Nati
  • 21
  • 1
  • `Student::Student(long id, char* name)` -- Are you changing `name` in any way in this function? If you are, be thankful for the error. – PaulMcKenzie Nov 04 '22 at 16:57
  • Change the parameter to `const char*`. See [Why is conversion from string constant to 'char*' valid in C but invalid in C++](https://stackoverflow.com/questions/20944784/why-is-conversion-from-string-constant-to-char-valid-in-c-but-invalid-in-c) – Jason Nov 04 '22 at 16:58
  • 1
    Why not use [std::string](https://www.learncpp.com/cpp-tutorial/introduction-to-stdstring/)? That's the goto datatype for strings since C++11. Using that will make all kinds of things you can do with strings much more easy ( == instead of strcmp, no more calls to strcpy and no more memory leaks). – Pepijn Kramer Nov 04 '22 at 17:01
  • `Student s1(123456789, std::strdup("someone"));` But you should be using `std::string` instead of micro-managing raw owning pointers to C-style C-string arrays. – Eljay Nov 04 '22 at 17:35

0 Answers0