相关疑难解决方法(0)

C++中的" - >"运算符是什么?

看完后隐藏功能和C++/STL的暗角comp.lang.c++.moderated,我完全惊讶的是,下面的代码片断编译并在两个Visual Studio 2008和G ++ 4.4的工作.

这是代码:

#include <stdio.h>
int main()
{
    int x = 10;
    while (x --> 0) // x goes to 0
    {
        printf("%d ", x);
    }
}
Run Code Online (Sandbox Code Playgroud)

我假设这是C,因为它也适用于GCC.标准中定义了哪里,它来自何处?

c++ code-formatting standards-compliance operators

8590
推荐指数
27
解决办法
75万
查看次数

取消引用NULL指针的哪一部分会导致意外行为?

我很好奇解除引用NULL ptr的哪一部分会导致不良行为.例:

//  #1
someObj * a;
a = NULL;
(*a).somefunc();   // crash, dereferenced a null ptr and called one of its function
                   // same as a->somefunc();

//  #2
someObj * b;
anotherObj * c;
b = NULL;
c->anotherfunc(*b);   // dereferenced the ptr, but didn't call one of it's functions
Run Code Online (Sandbox Code Playgroud)

在这里我们在#2中看到我实际上并没有尝试从b中访问数据或函数,所以如果*b刚解析为NULL并且我们将NULL传递给anotherfunc(),这仍会导致意外行为吗?

c++

2
推荐指数
1
解决办法
2528
查看次数