V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
erDaren
V2EX  ›  问与答

如果用包含柔性数组的结构体组成一个数组,那么应该怎么声明与定义?

  •  
  •   erDaren · 2015-10-21 09:09:01 +08:00 · 1386 次点击
    这是一个创建于 3171 天前的主题,其中的信息可能已经有所发展或是发生改变。

    像这样吗?还有没有别的更好的方法
    #include <stdio.h>
    #include <stdlib.h>

    typedef struct _user{
        int total_score;
        int pefect_score;
        int scores[];
    }User;
    
    int main()
    {
        int user_num, problem_num;
        scanf("%d %d", &user_num, &problem_num);
        User* users = (User*)malloc(user_num * (sizeof(User) + problem_num*sizeof(int)));
    
        return 0;
    }
    
    第 1 条附言  ·  2015-10-21 09:58:48 +08:00
    忘说了,我用的 C
    1 条回复    2015-10-21 09:22:22 +08:00
    MCVector
        1
    MCVector  
       2015-10-21 09:22:22 +08:00
    如果是 C++ 的话,我会在 struct 里 加 con/destructor. C 的话我想能不能在外面实现一个 con/desstructor.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3426 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 04:26 · PVG 12:26 · LAX 21:26 · JFK 00:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.