我得到了以下错误,我尝试了这两种方式,但没有解决它.
下面是代码
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
struct temp {
Stat_S sp("ppin");
}
Run Code Online (Sandbox Code Playgroud)
错误:字符串常量之前的预期标识符
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
const char *temp="ppin";
struct temp {
Stat_S sp(temp);
}
Run Code Online (Sandbox Code Playgroud)
错误:'temp'不是一种类型
class Stat_S{
public:
Stat_S(const char *name) :
{
........
}
~Stat_S();
};
struct temp {
Stat_S*sp = new Stat_S("ppin");
}
Run Code Online (Sandbox Code Playgroud)
工作很好没有错误
main()
{
static temp2 *temp;
temp2 = new temp[2];
}
Run Code Online (Sandbox Code Playgroud)
如何解决第一或第二案件?我想从struct temp调用Stat_S的构造函数.我不会使用第三种情况,因为我已经有了使用dot(.)作为sp的大定义我不想在使用实例后将其更改为 - >.
可以使用大括号或相等的初始化程序来执行非静态成员的类内初始化.第三种情况是使用相等的实例.要正确执行第1个或第2个,请使用以下大括号:
struct temp {
Stat_S sp{"ppin"};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4828 次 |
| 最近记录: |