0

I have a simple code which is basically like the one below:

static  std::string const part1[] = {"Test1", "Test2", "Test3"};

static  std::string const part2[] = {"Pass", "Fail", "Retry"};

std::string test = part1[1] + part2[0];

I have included the string which in turn has the basic_string.h. I know that there is an overloaded +operator there. When I built this I got no errors but when I tried to run it, I got a segmentation error. The problem I noticed later is that if I simply try to print the array elements, I am seeing the same segmentation error. I don't see where the memory leak is happening. Any clues?

4

1 回答 1

0

在 c++ 中,数组声明不可能以您在代码中使用的方式进行。

一个有效的代码示例是

static  std::string const part1[] ={"Test1", "Test2", "Test3"};
static  std::string const part2[] = {"Pass", "Fail", "Retry"};

std::string test = part1[1] + part2[0];
于 2013-05-29T04:49:35.150 回答