小编0x0*_*x01的帖子

复制构造函数中的C++向量数组

我是新手复制构造函数,当我开始使用向量时似乎无法让它们工作.

//  ROBOT CLASS
class Robot {
    private:
        char *name;
        int size;

        int cmdCount;

        command *cmdList;
        char items[8][16];
        int resources[3]; // silver, gold, then platinum

    public: 
        Robot( );
        Robot(int num_of_cmds, const char *nm);
        Robot(const Robot &);
        ~Robot( );

        const char *get_name( );
        command get_command(int pos) const;
        void set_item(const char item[ ], int pos);
        const char *get_item(int pos);

};

//  ROBOT CONSTRUCTOR default
Robot::Robot( ) {

    //  Load Robot name
    cmdCount = 5;
    try {
        name = new char[11];
    }
    catch(std::bad_alloc) …
Run Code Online (Sandbox Code Playgroud)

c++ constructor pointers vector

0
推荐指数
1
解决办法
1467
查看次数

标签 统计

c++ ×1

constructor ×1

pointers ×1

vector ×1