为什么我会得到这一行的错误?
void Student::SetName(const string newName)
{
if(newName!=NULL) //could not deduce template argument for 'const T1 *' from 'int'
{
.....
}
有什么想法吗?
发布于 2012-04-15 16:44:04
可能的解决方案:
if(!newName.empty())
if(newName.size()) // If size = 0 so no caracters in string
if(newName == "") // Empty string
发布于 2012-04-15 16:37:04
这不是C#,C++中的字符串不是可以为空的类型。只有指针才能为空,除非你使用的是指针,否则你不能定义一个变量,除非你在C++中给它赋了一些基本值。
您的代码可能如下所示:
if(!newName.empty())
....
https://stackoverflow.com/questions/10163840
复制