c++ struct结构体初始化

#include <stdio.h>

#include <memory.h>


struct MYSTRUCT {

int i, j, q;

char szName[15];

MYSTRUCT(){

i = j = q = 5;

memset(szName, 0, sizeof(szName));

}

};


struct Instance

{

char* buffer;

int texture;


Instance():

buffer(0),

//texture(0)

texture(5)

{

}

};


int main(void)

{

    structMYSTRUCT mystruct;

printf("mystruct.i=%d\n", mystruct.i);

Instance* instance = 0;

instance = new Instance();

if (0 == instance)

{

}

printf("text=%d",instance->texture);


printf("hi,%s\n", __DATE__);

#if defined(__YEAR__) && defined(__MONTH__) && defined(__DAY__)

#endif

#if defined(__YEAR__)

printf("hi,%s\n", __YEAR__);

#endif

while (1) {

//system("date");

//sleep(5);

}

return 0;

}

xushixiong@Cpl-Civil-Camera:~/data/remote_linux_C$ gcc -g test.cpp

/tmp/ccxS8SQL.o: In function `main':

/workteam/xushixiong/data/remote_linux_C/test.cpp:32: undefined reference to `operator new(unsigned long)'

collect2: ld 返回 1

xushixiong@Cpl-Civil-Camera:~/data/remote_linux_C$ g++ -g test.cpp  

xushixiong@Cpl-Civil-Camera:~/data/remote_linux_C$ ./a.out 

mystruct.i=5

text=5hi,Dec 16 2015


你可能感兴趣的:(C++,c,struct)