#include<iostream>
using namespace std;
class String
{
public:
String ( const char *c = NULL);
~String ();
bool operator!() const;
private:
char *elems;
};
String::String(const char *c)
{
elems = c;
}
String ::~String()
{}
bool String::operator!() const
{
if(elems == NULL)
return true;
else
return false;
}
int main(void)
{
String str;
if(!str)
cout<<"這是一個空字符串!"<<endl;
return 0;
}
程序出錯了,是char* 不能賦值給 const char * 這種錯誤怎麼改 (最好不把const刪掉),謝謝各位
強制轉換一下既可
elems = (char *)c;