C ++:vector< string> * args = new vector< string>();导致SIGABRT [英] C++: vector<string> *args = new vector<string>(); causes SIGABRT

查看:221
本文介绍了C ++:vector< string> * args = new vector< string>();导致SIGABRT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很自我解释。下面是在新向量行上引起SIGABRT的方法:

Pretty self explanatory. Here's the method that's causing the SIGABRT on the 'new vector' line:

vector<string> * Task::arguments() {
    vector<string> *args = new vector<string>(); // CAUSES SIGABRT
    int count = sizeof(_arguments);
    for (int x = 0; x < count; x++) {
        string argument(_arguments[x]);
        args->push_back(argument);
    }
    return args;
}

注意,在其他地方,我调用这个确切的行没有任何问题。下面是Task类中包含的列表:

Note that elsewhere I call that exact line without any issues. Here is the list of includes in the Task class:

#include <vector>
#include <unistd.h>
#include <string>
using namespace std;
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>

任何想法?

推荐答案

int count = sizeof(_arguments); 似乎很可疑。

sizeof 给出了以字节为单位的大小,而不是数组的数量(除非每个元素恰好是一个字节,即 char )。

sizeof gives you size in bytes, not number of elements an array (except in the case where each element is exactly one byte, i.e. char).

hth。,

这篇关于C ++:vector&lt; string&gt; * args = new vector&lt; string&gt;();导致SIGABRT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆