クラスmyStringを作成し、次のコードを実行しようとしています。
class myString{
char* str;
int len;
public:
myString(char* str1 = " "){
len = strlen(str1);
str = new char[len+1];
strcpy(str, str1);
};
int getLen() const {
return len;
};
char* getString() const {
return str;
};
~myString(){
delete[] str;
};
myString& operator=(myString& orig){
cout << "hello";
if (str == NULL){
delete[] str;
};
str = new char[orig.getLen()];
strcpy(str, orig.getString());
cout << this << endl;
return *this;
};
...
};
int main(){
myString s("bla");
myString k("dingo");
myString g = s;
// s=k; //When this line is commented I get a linking error
...
};
私の質問:
- なぜ「こんにちは」が印刷されないのですか?
s=k
その行がリンカーエラーを引き起こすのはなぜですか?
これはエラーです:
リンク:c:\ users \ perry \ document \ visual studio 2010 \ Projects \ inheritance \ Debug \ inheritance.exeが見つからないか、最後の増分リンクでビルドされていません。フルリンクの実行1>main.obj:エラーLNK2019:未解決の外部シンボル "class std :: basic_ostream>&__ cdecl operator <<(class std :: basic_ostream
&、class myString *) "(?? 6 @ YAAAV?$ basic_ostream @ DU?$ char_traits @ D @ std @@@ std @@ AAV01 @ PAVmyString @@@ Z)関数" public:class myString&__ thiscall myString :: operator =(class myString&) "(?? 4myString @@ QAEAAV0 @ AAV0 @@ Z)1> c:\ users \ perry \ document \ visual studio 2010 \ Projects \ inheritance \ Debug \ inheritance.exe:致命的なエラーLNK1120:1つの未解決の外観
ありがとう、李