用c结构体来实现c++中类的概念,下面是代码片段
#include <stdio.h>
struct TEST
{
TEST();
~TEST();
int a;
int b;
public:
int sum_t(int a,int b);
void print()
{
printf("this is %d----%d\n",a,b);
}
};
TEST::TEST() //构造函数
{
}
TEST::~TEST() //析构函数
{
}
int TEST::sum_t(int a,int b)
{
return (a + b);
}
int main(int argc, char *argv[])
{
struct TEST * test= new TEST();
test->a = 1;
test->b = 2;
test->print();
printf("test->sum === %d\n",test->sum_t(1,2));
return 0;
}