1
我收到以下错误,我试过2种方法,但没有解决它。错误:字符串常量或错误之前的预期标识符:'perf'不是一个类型
下面是代码
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
struct temp {
Stat_S sp("ppin");
}
错误:字符串常量前的期望标识符
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
const char *temp="ppin";
struct temp {
Stat_S sp(temp);
}
错误: '温度' 不是一个类型
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
struct temp {
Stat_S*sp = new Stat_S("ppin");
}
工作的优良任何错误
main()
{
static temp2 *temp;
temp2 = new temp[2];
}
如何解决第一或第二种情况?我想从struct temp调用Stat_S的构造函数。我不会使用第三种情况,因为我已经有了使用点(。)作为sp的大定义,我不想在使用实例后将其更改为 - >。
你想要做什么?在'struct temp'里面,你不应该编写可执行代码,而是成员。代码进入功能,而不是结构。如果你想有一个立即初始化的成员,那么你需要'='或'{}'语法。你的语法只适用于局部变量(也就是在一个函数内) – leemes 2015-01-21 00:14:50
为什么是负值点。你能解释一下吗,下次我会更加谨慎。 – eswaat 2015-01-21 00:16:06
我没有低调,但我想这是因为你没有解释你想要做什么。 – leemes 2015-01-21 00:16:50