C++结构体和类

#include "stdafx.h"
using namespace std;

class Test
{
public:
    int i;

    int getTest()
    {
        return i;
    }
};

typedef struct _tag_Test
{
    int i;
} TEST;

int _tmain(int argc, _TCHAR* argv[])
{
    TEST* t = new TEST;
    t->i = 1;

    Test* tt = (Test*)t;

    printf("%d \n", tt->getTest());
    printf("%d \n", tt->i);
    getchar();
    return 0;
}
struct和class好像没什么太大的区别,详见请阅读《C++编程思想》
posted @ 2015-04-28 16:31  河豚  阅读(139)  评论(0编辑  收藏  举报