zoukankan      html  css  js  c++  java
  • C语言实现类

    #ifndef __DEFINE__H__
    #define __DEFINE__H__
    
    #define vector3(type) 
    typedef struct vector3_##type { 
        type a; 
        type b; 
        type c; 
    }vector3_##type;  // vector3##_type会报错 
    
    #define ABS_CLASS(type)             
    typedef struct cl_##type cl_##type; 
    struct cl_##type  // 没有这一行会报错 
        
    vector3(int); // 用来初始化其后面的内容 
    
    #endif

    上面是"define.h"文件

    #include<stdio.h>
    #include"define.h"
    
    ABS_CLASS(float){
        float a;
        float b;
        float c;
        float d;
        float (*sum)();
    };
    
    cl_float vecf4={10.0,20.0,30.0,40.0,NULL};
    
    float sum(cl_float cl)
    {
        return cl.a+cl.b+cl.c+cl.d;
    }
    
    
    int main()
    {
        vector3_int vec;
        vec.a=10;
        vec.b=20;
        vec.c=30;
         vecf4.sum=sum;
        printf("vec.a+vec.b+vec.c=%d
    ",vec.a+vec.b+vec.c); 
        printf("vecf4.sum=%f
    ",vecf4.sum(vecf4)); 
        return 0;
    }
  • 相关阅读:
    阿牛的EOF牛肉串
    盐水的故事
    密码
    Digital Roots
    不容易系列之(3)—— LELE的RPG难题
    不容易系列之一
    超级楼梯
    母牛的故事
    蟠桃记
    Children’s Queue
  • 原文地址:https://www.cnblogs.com/ligei/p/12520002.html
Copyright © 2011-2022 走看看