小编bee*_*hnu的帖子

指向数组的指针的地址

下面是二维数组的示例.

int s[5][2] = {
            {0, 1},
            {2, 3},
            {4, 5},
            {6, 7},
            {8, 9}
        };

int (*p)[2];
Run Code Online (Sandbox Code Playgroud)

如果我写,p = &s[0];那就没有错误.但是如果我写的p = s[0];是有错误,即使&s[0]并且s[0]会给出相同的地址.

请告诉我为什么会有不同之处,即使两者都给出相同的地址.

c arrays pointers multidimensional-array

8
推荐指数
1
解决办法
204
查看次数

Start thread within member function using std::thread & std::bind

I have few queries with respect to below code snapshot.

1) With respect to pthread_create(), assume Thread_1 creates Thread_2. To my understanding Thread_1 can exit without join, but still Thread_2 will keep running. Where as in below example without join() I am not able to run thread and I am seeing exceptions.

2) In few examples I am seeing thread creation without thread object as below. But when I do the same, code is terminated.

std::thread(&Task::executeThread, this);

I am compiling …
Run Code Online (Sandbox Code Playgroud)

c++ multithreading c++11

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

我们是否可以使用 [] 而不是 Push_back() 来初始化向量

作为向量的一部分,使用 [] 我无法初始化。

std::vector<int> vectorVar;
vectorVar[0] = 0;
Run Code Online (Sandbox Code Playgroud)

看到未定义的行为。

而只有在已经创建的情况下才能使用。

vectorVar.push_back(0);
vectorVar[0] = 5;
Run Code Online (Sandbox Code Playgroud)

但如果有地图,即使没有条目也可以使用。

std::map<int, std::vector<int>> mapVar;
mapVar[0] = vectorVar;
Run Code Online (Sandbox Code Playgroud)

请澄清。

感谢和问候 毗湿奴比玛

如果“vectorVar[0] = 0;”,则会出现未定义的行为

c++ stl vector stdvector

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