首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

运算符重载的有关问题。请高手看下

2012-03-09 
运算符重载的问题。请高手看下61// concatenate right operand to this object and store in this object62

运算符重载的问题。请高手看下
61 // concatenate right operand to this object and store in this object
62 const String &String::operator+=( const String &right )
63 {
64 size_t newLength = length + right.length; // new length
65 char *tempPtr = new char[ newLength + 1 ]; // create memory
66
67 strcpy( tempPtr, sPtr ); // copy sPtr这里
68 strcpy( tempPtr + length, right.sPtr ); // copy right.sPtr这里
69
70 delete [] sPtr; // reclaim old space
71 sPtr = tempPtr; // assign new array to sPtr
72 length = newLength; // assign new length to length
73 return *this; // enables cascaded calls
74 } // end function operator+=
编译时提示:warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
67行我改成:strcpy_s( tempPtr,newLength+1, sPtr )通过了
68行我不会改,请高手看下!

[解决办法]
strcpy_s( tempPtr,newLength+1, sPtr )
to
strcpy_s( tempPtr,length, sPtr )

热点排行
Bad Request.