- リスト###前提・実現したいこと
下記エラーが発生してしまい、解決できません。
基本的なことで申し訳ないですが、教えてください。
###発生している問題・エラーメッセージ
Main.cpp:11:2: error: no matching function for call to 'strcpy'
strcpy(this->name, "undifined");
^~~~~~
/usr/include/string.h:129:14: note: candidate function not viable: no known conversion from 'char *[100]' to 'char *restrict' for 1st argument
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
^
Main.cpp:17:2: error: cannot delete expression of type 'char *[100]'
delete[] name;
^ ~~~~
Main.cpp:29:5: error: no matching function for call to 'strcpy'
strcpy(w1.name, "Takayuki");
^~~~~~
/usr/include/string.h:129:14: note: candidate function not viable: no known conversion from 'char *[100]' to 'char *restrict' for 1st argument
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
^
3 errors generated.
###ソースコード
<ヘッダーファイル> class Worker{ public: int number; char* name[100]; double salary; Worker(); ~Worker(); }; <メイン文> #include <iostream> using namespace std; #include <iostream> #include "string.h" #include "Worker.h" using namespace std; Worker::Worker(){ //name = new char[80]; strcpy(this->name, "undifined"); number = 0; salary = 0; } Worker::~Worker(){ delete[] name; } void ShowData(Worker* w1){ cout << "name = " << w1->name << "\n"; cout << "number = " << w1->number << "\n"; cout << "salary = " << w1->salary << "\n"; } int main(){ Worker w1; strcpy(w1.name, "Takayuki"); ShowData(&w1); return 0; }
###補足情報(言語/FW/ツール等のバージョンなど)
paiza.io
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/01/21 01:56