首页 > TAG信息列表 > object-lifetime

c# – .NET – 终结器并退出(0)

我有一个.NET C#/ C应用程序,它使用一个线程中的exit(0)(来自< stdlib.h>)来终止. 奇怪的是,在某些情况下,托管对象的终结器在调用退出后立即被调用,而在其他情况下,它们根本不被调用. 这种情况非常确定 – 应用程序在其生命周期内从外部插件dll(用非托管C编写)调用一些方法. 如果

c – 在C函数中创建的对象的存在

已经建立(见下文)placement new是创建对象所必需的 int* p = (int*)malloc(sizeof(int)); *p = 42; // illegal, there isn't an int 然而,这是在C中创建对象的一种非常标准的方式. 问题是,如果在C中创建int并返回到C,那么它是否存在? 换句话说,以下是否保证合法?假设int对于C和C

c – 对象被销毁后,标量类型的子对象会发生什么?

请考虑此代码(针对续订和清理的不同值): struct T { int mem; T() { } ~T() { mem = 42; } }; // identity functions, // but breaks any connexion between input and output int &cleanse_ref(int &r) { int *volatile pv = &r; // could also use cin/cout

c – 为什么我不能在多重继承期间“侧向”动态广播?

以下代码抛出std :: bad_cast struct Foo { void foo () {} }; struct Bar { Bar () { dynamic_cast <Foo &> (*this) .foo (); } virtual ~ Bar () {} }; struct Baz : public Foo, public Bar { }; int main () { Baz b; } 我记得曾经读过dyn

c – 为什么非const引用参数可以绑定到临时对象?

char f1(); void f2(char&); struct A {}; A f3(); void f4(A&); int main() { f2(f1()); // error C2664. This is as expected. f4(f3()); // OK! Why??? } error C2664: ‘void f4(char &)’ : cannot convert argument 1 from ‘char’ to ‘c

c – std :: initalizer_list可以导致生命周期问题吗?

使用std :: initializer_list时遇到了一些困难.没过多久就意识到我更多地将它想象成一个容器,实际上它具有引用语义.所以我的问题是,以下哪个例子可能会导致问题,如果没有,为什么它们会起作用? 我应该补充说我正在使用VS2013并且std :: initializer_list仅使用开始和结束指针实现.