C++结构体中初始化结构

来源:百度知道 编辑:UC知道 时间:2024/05/13 04:30:22
typedef struct _TestA
{
int a;
int b;
int c;
}TestA,*pTestA;
typedef struct _TestB
{
int ab;
TestA testa={0,0,0};
int cd;
}TestB,*pTestB;

为什么编译通不过??
这个只是定义在头文件"test.h"
主程序里面#include "test.h"

有main函数吗

#include<iostream>
using namespace std;
typedef struct _TestA
{
int a;
int b;
int c;
_TestA(int x=0,int y=0,int z=0):a(x),b(y),c(z){}
}TestA,*pTestA;

typedef struct _TestB
{
int ab;
TestA testa;
int cd;
_TestB();
}TestB,*pTestB;
_TestB::_TestB(){testa=TestA(2,0,0);}
int main()
{
TestB t;
cout<<t.testa.a;
return 0;
}

typedef struct _TestA
{
int a;
int b;
int c;
void _TestA(VOID)
{
a = 0;
b = 0;
c = 0;
};
}TestA,*pTestA;

typedef struct _TestA
{
int a;
int b;
int c;
}TestA,*pTestA;

TestA testa={0,0,0};//在这初始化

typedef struct _TestB
{
int ab;
TestA testa;
int cd;
}TestB,*pTestB;