###前提・実現したいこと
引数つきのコンストラクタを追加したところエラーが起き、原因が分かりません。
すいません、勉強して一週間もたっていなくて、質問が投げやりな感じになってしまって申し訳ありませんが、回答お願い致します。
###発生している問題・エラーメッセージ
Phone.cpp:17:3: error: no matching function for call to 'strcpy'
strcpy(this->plan,*plan);
^~~~~~
/usr/include/string.h:129:14: note: candidate function not viable: no known conversion from 'char' to 'const char *restrict' for 2nd argument; remove *
extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
^
Phone.cpp:37:21: warning: ISO C++11 does not allow conversion from string literal to 'char *' [-Wwritable-strings]
Phone p2(false, "p2","noraml");
^
1 warning and 1 error generated.
^
1 error generated.
###ソースコード
<メイン文> #include <iostream> #include <string.h> #include "Phone.h" using namespace std; Phone::Phone(){ plan = new char[100]; cout << "this is constrcuter "<< "\n"; this->i = false; strcpy(this->plan, "normal"); this->pInfo = "nokia"; } Phone::Phone(bool i, char* plan, string pInfo){ this->i = i; strcpy(this->plan,*plan); this->pInfo = "nokia"; } Phone::~Phone(){ } void Phone::ShowPhone(){ cout << " i = " << this->i << "\n"; cout << " plan = " << this->plan <<"\n"; cout << " pInfo = " << this->pInfo <<"\n"; } int main(){ cout << " main " <<"\n"; Phone p1; Phone p2(false, "p2","noraml"); p1.i = false; strcpy(p1.plan,"normal"); p1.pInfo = "nokia"; p1.ShowPhone(); return 0; } <ヘッダー文> #include <string.h> class Phone{ public: Phone(); Phone(bool i, char* plan, std::string pInfo); ~Phone(); bool i; char* plan; std::string pInfo; virtual void ShowPhone(); };
###補足情報(言語/FW/ツール等のバージョンなど)
paiza.io
回答1件
あなたの回答
tips
プレビュー