有人可以向我解释为什么这段代码有效吗?我觉得编译器不应该允许我做我做的事情(移动一个指针指向一个const int),或者我至少会期望编译器警告或段错误.改变常数值的想法似乎是错误的.
码:
#include <iostream>
using namespace std;
struct test_struct {
int i;
const int j;
};
int main() {
cout << "Create a struct with int i = 100 and const int j = 101." << endl;
test_struct test{100, 101};
cout << test.i << endl;
cout << test.j << endl;
cout << "Create pointer p and point it to int i." << endl;
int* p1 = &test.i;
cout << *p1 << endl;
cout << "Increment pointer p, which should …Run Code Online (Sandbox Code Playgroud) 因此,我一直在研究JavaScript实际上是单线程的,即使它似乎是多线程的(或者至少我是这样理解的),我想知道以下功能是否可以保证在其他功能之前完成叫做。
我相当确定它是,但是调用push()使我担心,在调用它时,可能会先执行其他一些功能。话虽这么说,我想不出会运行任何长时间运行的代码push()。
// adds a new node to children, after checking if its UID is not in childrenAdded
this.addChild = function(newChild) {
if (!_this._childrenAdded[newChild.uid]) {
_this._childrenAdded[newChild.uid] = true;
_this._children.push(newChild);
}
}
Run Code Online (Sandbox Code Playgroud)