我该怎么办在下面的代码对象明确初始化...显式声明的对象
#include"iostream"
using namespace std;
class per{
char *name;
int a;
public:
per(int x = 0,char *str = 0):a(x),name(str){}
char* get()
{
return name;
}
};
int main()
{
per obj(100,"test"); // works fine
// now if i want a explicit initialization for above how will i do?
// example -- per obj = (100,"test");
// but i am getting error or may be not aware how to use
return 0;
}
我需要明确的......上面的代码不起作用......我得到错误1> c:\ users \ badshah \ documents \ visual studio 2010 \ projects \ practice \ practice \ smart_class.cpp(34):错误C2440:'初始化':无法从'const char *'转换为'per' 1>没有构造函数可以采用源类型,或构造函数重载解析模糊 – 2013-02-20 18:41:31
适用于g ++! – Dilawar 2013-02-20 18:53:56
@Badshah - 你可能会在类中尝试'const char *',因为字符串常量是const。 – 2013-02-20 18:56:09