vc++6.0 中对结构体如何赋初值。

来源:百度知道 编辑:UC知道 时间:2024/05/12 10:02:03
例如:
struct node{
int a;
char b;
int *p1};
struct node node1[2]={
{1,'2',NULL},{3,'4',NULL}};
为什么不行

c++中类或结构体的初值必须在构造函数里(即与类,结构体名相同但没有返回值类型的函数,可重载)
像这样:
class node{
public:
int a;
char b;
int *p1
node(int ai,char bi, int *p1i)
{
a=ai;b=bi;p1=p1i;
}
};
node node10(1,'2',NULL),node11(3,'4',NULL);

这个好像没问题啊,可以把你编译时报的错误列出来再看看啊!