c++学习6 -- 结构体

#include <iostream>
using namespace std;

struct Node
{
    int m;
    void fun()
    {
        printf ("hello c++");
    }
};

int main()
{
    Node a;
    a.fun();
    system("pause");
    return 0;
}

//c++ 独有 生命变量可以不用struct关键字 、 可以放函数成员,c语言不可以放函数成员,但是可以放函数地址 、 是一个特殊的类

 

//c的用法

#include <stdio.h>


struct Node
{
    int m;
    void (*p)();
};
void fun()
{
    printf ("hello c");
}

int main(void)
{
    struct Node a = {1,fun};
    a.p();
    return 0;
}

 

posted on 2018-04-26 17:35  theslowman  阅读(87)  评论(0编辑  收藏  举报