精华内容
参与话题
问答
  • Destructor

    2020-11-28 08:18:28
    Such logic typically resides in a destructor callback, which could be called $deinit</code>. <p>What about adding such callback? Or what would be the alternatives?</p><p>该提问来源于开源项目:...
  • Destructor bomb

    2020-12-29 22:35:49
    <div><p>Introduce destructor-bombs to improve the (runtime) safety of the library.</p><p>该提问来源于开源项目:Munksgaard/session-types</p></div>
  • Array destructor

    2020-11-24 14:17:20
    ve implemented the array destructor storage compaction with support for merging and splitting w.r.t. the comment on <a href="https://github.com/hsutter/gcpp/blob/master/deferred_heap.h#L77">deferred_...
  • Private Destructor

    2017-05-03 16:03:16
    轉載自 http://www.geeksforgeeks.org/private-destructor/ ...Private Destructor Predict the output of following programs. #include using namespace std; class Test { private: ~Test() {} }; i

    轉載自 http://www.geeksforgeeks.org/private-destructor/

    Private Destructor

    Predict the output of following programs.

    复制代码
    #include <iostream>
    using namespace std;
     
    class Test
    {
    private:
       ~Test() {}
    };
    int main()
    { }
    复制代码

    The above program compiles and runs fine. It is not compiler error to create private destructors. What do you say about below program.

    复制代码
    #include <iostream>
    using namespace std;
     
    class Test
    {
    private:
       ~Test() {}
    };
    int main()
    { 
      Test t; 
    }
    复制代码

    The above program fails in compilation. The compiler notices that the local variable ‘t’ cannot be destructed because the destructor is private. What about the below program?

    复制代码
    #include <iostream>
    using namespace std;
     
    class Test
    {
    private:
       ~Test() {}
    };
    int main()
    { 
       Test *t;
    }
    复制代码

    The above program works fine. There is no object being constructed, the program just creates a pointer of type “Test *”, so nothing is destructed. What about the below program?

    复制代码
    #include <iostream>
    using namespace std;
     
    class Test
    {
    private:
       ~Test() {}
    };
    int main()
    { 
       Test *t = new Test;
    }
    复制代码

    The above program also works fine. When something is created using dynamic memory allocation, it is programmer’s responsibility to delete it. So compiler doesn’t bother.

    The below program fails in compilation. When we call delete, desturctor is called.

    复制代码
    #include <iostream>
    using namespace std;
     
    class Test
    {
    private:
       ~Test() {}
    };
    int main()
    { 
       Test *t = new Test;
       delete t;
    }
    复制代码

    We noticed in the above programs, when a class has private destructur, only dynamic objects of that class can be created. Following is a way to create classes with private destructors and have a function as friend of the class. The function can only delete the objects.

    复制代码
    #include <iostream>
     
    // A class with private destuctor
    class Test
    {
    private:
        ~Test() {}
    friend void destructTest(Test* );
    };
     
    // Only this function can destruct objects of Test
    void destructTest(Test* ptr)
    {
        delete ptr;
    }
     
    int main()
    {
        // create an object
        Test *ptr = new Test;
     
        // destruct the object
        destructTest (ptr);
     
        return 0;
    }
    复制代码

    What is the use of private destructor?
    Whenever we want to control destruction of objects of a class, we make the destructor private. For dynamically created objects, it may happen that you pass a pointer to the object to a function and the function deletes the object. If the object is referred after the function call, the reference will become dangling. See this for more details.


    展开全文
  • Improve CFReader destructor

    2020-12-27 02:09:53
    <div><p>This improves the CFReader's destructor, by testing for <code>self._dataset</code> to exist. It fixes #3312.</p><p>该提问来源于开源项目:SciTools/iris</p></div>
  • ObjectWrap and destructor

    2020-11-27 12:35:57
    m using global.gc() to call the destructor method of the class derived from ObjectWrap. Isn't it possible to do this automatically? Actually I don't want to use global.gc().</p><p>该提问来源于...
  • no destructor?

    2020-12-02 12:36:47
    <p>In order to save resources in such projects I though I would call the destructor on the dummy u8g2 object. <p>I tried: ~u8g2; and ~u8g2();</code></p> <p>but the compiler complains with: <p>error: ...
  • DisplayObjects destructor

    2020-12-30 12:28:23
    <div><p>I placed printf(&#...If destructor not calling it could be problem for applications where display objects creating and destroying actively.</p><p>该提问来源于开源项目:haxenme/nme</p></div>
  • m moving the destructor for <code>EventPIpeThread</code> on to the <code>Thread</code> object. This also moves the desctructor from being fired at process exit which can cause issues. <p>WIP for now ...
  • Exception in destructor

    2020-12-02 11:33:15
    <div><p><code>NodeRefListBuilder</code> and other ...<p>I think the <code>add_padding</code> needs to be moved outside of the destructor.</p><p>该提问来源于开源项目:osmcode/libosmium</p></div>
  • trivial destructor

    2013-10-30 14:25:23
    如果一个class没有定义destructor,如果这个class中的一个数据成员拥有destructor,那么编译器会自动合成出这个class的destructor来.在这个class的合成的destructor里调用那个数据成员的destructor,这个合成的 class的...
    trivial理解为无用的,无意义的;     non-trivial自然就是有实际意义的
    
    如果一个class没有定义destructor,如果这个class中的一个数据成员拥有destructor,那么编译器会自动合成出这个class的destructor来.在这个class的合成的destructor里调用那个数据成员的destructor,这个合成的 class的destructor是有意义的,即是non-trivial的.  
      如果这个class没有上述的那种数据成员,那么编译器并不会合成出一个destructor来,这时,可以“理解”为这个destructor是trivial的,当然实际上destructor是不存在的.
    
    比如  
      class   A  
      {  
          int   i;  
          int   j;  
      }  
      根本没有必要去调用析构函数,所以这时候,编译器对delete基本上不会生成析构的代码。  
      non   trivial   destructor则反之
    展开全文
  • Component destructor call

    2021-01-11 05:42:49
    <p>On the second assignment for entity <code>ent2</code> the velocity destructor is called for <code>ent1</code>. It's a bit weird, maybe I don't understand it, but I was pretty sure that ...
  • destructor, sync option

    2020-11-25 16:25:49
    <div><p>I suggest you add and option for the destructor to sync. Something like m.destructor_sync(true); <p>I believe there are use cases when data is being updated, where forgetting to sync could be ...
  • Destructor\n")} }; int main() { { entt::registry registry; entt::entity someEntity; someEntity = registry.create(); registry.emplace<somecomponent>(someEntity); registry.remove<...
  • <p>It looks like 4 distinct objects are being constructed but the destructor of one of the objects is being invoked 4 times.</p><p>该提问来源于开源项目:boost-ext/di</p></div>
  • Bison之destructor

    2019-11-01 10:43:09
    因为我一开始以为,在每次销毁token的时候都会调用这个destructor。因为我的token有的会带有指针类型的值,但却并不是所有匹配规则都会用到这个指针指向的值。所以我以为只要设置了destructor,在每次匹配成功一个...

    前两天看到了这个用法。

    感觉这个关键词感觉还是挺误导人的。
    因为我一开始以为,在每次销毁token的时候都会调用这个destructor。因为我的token有的会带有指针类型的值,但却并不是所有匹配规则都会用到这个指针指向的值。所以我以为只要设置了destructor,在每次匹配成功一个规则的时候,就不用手动去释放没有用到的token了。结果并!没!有!

    原来,这个destructor,只有在发生错误,要扔掉token的时候才会被调用

    比如:

    %union{
    	int* i;
    }
    %token<i> INT
    %destructor { delete $$; } <i>
    
    %%
    
    rule1: INT '+' INT
    	{
    		$$ = $1;
    		*($$) += *($3);
    		delete $3;
    		$1 = $3 = nullptr;
    	}
    

    假设其中token INT为匹配一个整型。
    那么当输入为1 + 3的时候,成功匹配到规则rule1的时候,destructor并不会被调用。此时必须手动释放$3指针指向的空间。
    但是如果输入为3 - 1的时候,减号-匹配失败,发生错误,此时栈中的两个token:INT和‘-’会被扔掉,此时,在扔掉INT token的时候,才会调用对应的destructor。

    所以,destructor其实是用来防止发生错误时可能导致的内存泄漏。

    展开全文
  • ve called a destructor method or received a destructor event, you <em>must not</em> use the object again, or it may completely mess up the internal state of the C library. <p>This is obviously <em>...
  • Add destructor to Task

    2020-12-27 07:41:09
    <div><p>This ensures that a task is deleted from the scheduler when its destructor gets called, i.e. it goes out of scope.</p><p>该提问来源于开源项目:arkhipenko/TaskScheduler</p></div>
  • <div><p>With the code test matrix_destructor in testsuite/feelleaks I noticed that the allocated memory for a matrix have a strange behavior after calling the matrix destructor. Maybe naively I expect...
  • <div><p>Destructor of the m_work in websocketpp/transport/asio/endpoint.hpp tries to access destroyed m_io_service after the last one was already deleted in the ~endpoint(). </p><p>该提问来源于开源...
  • <p>Destructor does not agree to do his job. <h4>What happens: <p>Nothing <h4>What you expected to happen: <p>Breaks the block. <h4>Steps to reproduce: <ol><li>Build Destructor and connect to rs system...
  • C++中的trivial destructor 转:http://blog.csdn.net/wudishine/article/details/12307611   如果用户不定义析构函数,而是系统自带的,那么说明析构函数基本没什么用(但默认会被调用)。我们称之为trivial ...

    C++中的trivial destructor
    转:http://blog.csdn.net/wudishine/article/details/12307611
      如果用户不定义析构函数,而是系统自带的,那么说明析构函数基本没什么用(但默认会被调用)。我们称之为trivial destructor。反之,如果特别定义了析构函数,则说明需要在释放空间之前做一些事情,则这个析构函数称之为non-trivial destructor。如果某个类中只有基本类型的话是没有必要调用析构函数的,delete的时候基本不会产生析构代码。
      在C++的类中如果只有基本的数据类型,也就不需要写显式的析构函数,即用默认析构函数就够用了,但是如果类中有个指向其他类的指针,并且在构造时候分配了新的空间,则在析构函数中必须显式释放这块空间,否则会产生内存泄露。
      在STL中空间配置时候destory()函数会判断要释放的迭代器的指向的对象有没有 trivial destructor(STL中有一个 has_trivial_destructor函数,很容易实现检测)放,如果有trivial destructor则什么都不做,如果没有即需要执行一些操作,则执行真正的destory函数。destory()有两个版本,第一个版本接受一个指针,准备将该指针所指之物析构掉,第二个版本接受first和last两个迭代器,准备将[first,last]范围内的所有对象析构掉。我们不知道这个范围有多大,万一很大,而每个对象的析构函数都无关痛痒,那么一次次调用这些析构函数,对效率是一种伤害,因此这里首先利用value_type()获得迭代器所指对象的类别,再利用_type_traits判断该型别的析构函数是否无关痛痒,若是(_true_type),则什么也不做就结束,若否(_false_type),这才以循环的方式巡访整个范围,并在循环中每经历一个对象就调用第一个版本的destory()。

    展开全文
  • t go out and keeps calling the List destructor. i've tried letting it do it for hours and still the same issue it never get out of it.</p><p>该提问来源于开源项目:cparse/cparse</p></div>
  • No Destructor Generated?

    2021-01-03 06:48:15
    <div><p>I have the following class: <pre><code> class __declspec(dllexport) MyClass ...t see it trying to execute my destructor method at all.</p><p>该提问来源于开源项目:mono/CppSharp</p></div>
  • non-trivial自然就是有实际意义的如果一个class没有定义destructor,如果这个class中的一个数据成员拥有destructor,那么编译器会自动合成出这个class的destructor来.在这个class的合成的destructor里调用那个数据成员...
  • the log4cplus is blocked at threadpool destructor <code>condition_consumers.notify_all(); and the only way to exit is call TerminateProcess(GetCurrentProcess(), 0);</p><p>该提问来源于开源项目:...
  • Virtual Destructor

    2013-11-26 21:07:00
    Deleting a derived class object using a pointer to a base class that has a non-virtual destructor results in undefined behavior. To correct this situation, the base class should be defined w...
  • <div><p>Fixes https://github.com/ros-simulation/gazebo_ros_pkgs/issues/354 with the destructor warning: <pre><code> terminate called after throwing an instance of 'boost::exception_detail::clone_...
  • <div><p>https://stackoverflow.com/questions/630950/pure-virtual-destructor-in-c</p><p>该提问来源于开源项目:CppMicroServices/CppMicroServices</p></div>
  • <div><p>I find <a href="https://github.com/MADEAPPS/newton-dynamics/blob/de0ac32822a83d735627d4f7f7962aa0448ea3ae/sdk/dContainers/dBaseHierarchy.cpp#L27" title="Update candidate: Destructor for ...

空空如也

1 2 3 4 5 ... 20
收藏数 4,493
精华内容 1,797
关键字:

destructor