统一的类调用函数,没有例外.这是怎么回事
Unitialized Class Calling Function, No exception. What is going on here?
这是正常行为吗?我以前从没遇到过这种事。我认为它会导致异常,但为什么这里没有呢?看一看
<>之前
CWindowsApplication::MsgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static CWindowApplication* pApp = NULL;
if (message == WM_NCCREATE)
{
//// retrieve Window instance from window creation data and associate
//pApp = reinterpret_cast(((LPCREATESTRUCT)lParam)->lpCreateParams);
//::SetWindowLong(hWnd, GWL_USERDATA, reinterpret_cast(pApp));
//pApp = reinterpret_cast(::GetWindowLong(hWnd, GWL_USERDATA));
}
pApp->WndProc(hWnd, message, wParam, lParam); // pApp = NULL, but it still works? I expected a exception of some sort.
}
之前但是,当我将类更改为其他东西时,我得到了我期望的异常。这是怎么回事?在我作为一个充满热情的程序员的10多年里,我从来没有遇到过这样的事情。
只要WndProc
不是虚的,从技术上讲,为了进行调用,指针根本不需要解引用。这并不是说当您尝试在WndProc
中使用this
(包括调用带有隐式this
的任何虚函数)时它不会崩溃和燃烧,但是非虚调用根据指针的类型进行,并且不需要触摸虚表(或任何其他实例成员)。
你所做的就是调用未定义的行为。这意味着它可以工作,也可以崩溃,或者编译器想让它做什么就做什么。
相关文章:
- 使用递归的数组的最小值.这是怎么回事
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 我使用 OpenMP 的线程越多,执行时间就越长,这是怎么回事?
- 绕道重铸瓷砖层是怎么回事
- 架 (U+67B6) 与en_US不符.UTF-8.这是怎么回事?
- R 中的算术在数字上比整数更快。这是怎么回事?
- 我的代码运行良好,但现在当尝试将其制作成模板时,我遇到了许多看似无关的错误。这是怎么回事?
- 在变量名后声明带有 () 的非内部类型与不使用变量名的行为不同。即 std::map<int,char>x(); - 这是怎么回事?
- 弄清楚这段代码是怎么回事(递归下降案例研究)
- 分配器密集和稀疏是怎么回事?
- 传递引用C++,指针的向量.这是怎么回事?
- __vector_base_common是怎么回事?
- (对象)不命名类型.怎么回事
- 变量已在 .obj 中定义;这是怎么回事?
- Sublime上的EasyClangComplete是怎么回事?
- 重复输出的类型是怎么回事,它如何区分迭代次数和 Ascii 代码?
- 标准::地图使用.这是怎么回事?核心转储?我做得不正确?
- llvm libcxx的源代码是怎么回事?
- 这一行是怎么回事: istringstream is( line );
- 统一的类调用函数,没有例外.这是怎么回事