#include <iostream>
#include <cstring>
using namespace std;
private:
char * name;
char * company;
char * tel;
int position;
public:
Namecard(char * n, char * c, char * t, int pos) :position(p)
{
name = new char[strlen(n) + 1];
company = new char[strlen(c) + 1];
tel = new char[strlen(t) + 1];
strcpy(name, n);
strcpy(company, c);
strcpy(tel, t);
}
void showcard() {
cout << "이름: " << name << endl;
cout << "회사: " << company << endl;
cout << "전화: " << tel << endl;
cout << "직책: "; COMP_POS::showposition(position);
}
~Namecard() {
delete[]name;
delete[]company;
delete[]tel;
}
};
int main(void)
{
Namecard manclerk("Lee," "ABC", "010-2222-1111", COMP_POS::CLERK);
Namecard mansenior("kim," "DEF", "010-3222-5555", COMP_POS::SENIOR);
Namecard manassist("park," "SAM", "010-7777-1111", COMP_POS::ASSIST);
return 0;
}
I set the constructor as above in the main function An error appears stating that no instance of constructor namecard::namecard matches the list of arguments Can you tell me what's wrong and how to fix it?
c++
C++ has stricter parameter formatting than C. You must specify const char *
to receive a C style string as a parameter.
Namecard(char * n, char * c, char * t, int pos) :position(p)
You can change the line above like below.
Namecard(const char* n, const char* c, const char* t, int pos) :position(p)
© 2024 OneMinuteCode. All rights reserved.