G++ (FreeBSD) 错误: '{'令牌之前预期的主表达式

g++ (freebsd) error: expected primary-expression before '{' token

本文关键字:表达式 令牌 错误 FreeBSD G++      更新时间:2023-10-16

我有一些代码在使用g++的ubuntu中运行良好但未能在freebsd中编译,我不知道为什么

//in the source body MyClass.cpp
        void MyClass::app_init()
        {
            funcs[0] = { &MyClass::app_map, 4 };
            funcs[1] = { &MyClass::app_pro, 10 };

        }

        //in the header   MyClass.h
        public:
        struct foo
        {
            int fd;
            time_t ts;
        };
        struct func
        {
            void (MyClass::*f) (foo *);
            int arg_length;
        };

        void app_init();
        void app_map(foo *a);
        void app_pro(foo *a);
        private:
        func funcs[FUNCS_ARRAY];    //2
funcs[0] = (func){ &MyClass::app_map, 4 };
...

或使用g++ --std=c++11 ... 编译