destructor

    0热度

    2回答

    我在多图中使用对象作为关键字,如下所示。我只有一个类数据实例:Data d1(1,2)。 #include <iostream> #include <string> #include <map> using namespace std; class Data{ public: static int counter; Data(int x = 0, in

    0热度

    2回答

    在为例第一静态断言以下燃煤而不是第二: #include<type_traits> struct A{ protected: ~A()=default; }; struct B:A{ //this static assertion fails static_assert(std::is_trivially_destructible<A>::value,"");

    2热度

    1回答

    我可以专注析构函数的一个案例,但我无法告诉编译器只使用任何其他情况下,一个正常的析构函数: #include <iostream> template <int = 0> struct Foo { ~Foo(); }; int main() { { Foo<> a; // Normal destructor called } {

    0热度

    1回答

    This看起来类似于我所在的位置以及this问题。 考虑以下 template<typename T> class A { private: class B { private: B* link; public: B(); ~B(); }; B* head; public:

    3热度

    1回答

    为以下包装类跟上std::unique_ptr中间对象来访问me成员而不复制me的“OK”的方式? 下面是示例 #include <iostream> #include <memory> /* myobj from another library */ class myobj { public: std::string me; /* actual member of inter

    0热度

    1回答

    所以这里的东西..我有一个对象是负责创建另一个不同的对象,这个创建的对象可以被销毁或不(取决于用户)。技巧部分是再次调用“创建者”对象,如果另一个对象没有被删除,这个类不能再次创建这个对象,但是如果另一个对象被删除了,这个类需要重新创建并且循环继续。 我试过2个解决方案: 全局变量作为“旗”,它工作正常,但我烤全球变量使用; 第二个是使析构函数返回一个值给这个标志,但我不能从析构函数返回。 你知道

    3热度

    1回答

    我有一个带有指向整数的指针的类。 然后一个静态函数将返回该整数的值。 我注意到当调用静态函数时,每次都会为该对象调用析构函数。 我不明白为什么会发生这种行为。 class Dog { public: Dog(int val){ this->pVal = new int(val); } ~Dog(){ delete this->pVal; } static int GetVa

    0热度

    2回答

    我正在为一个CS项目的矩阵类工作,我试图在构造函数上工作。该项目调用两个不同的构造函数,一个调用行数和列数,并使其全部为0,另一个使用初始化程序列表分配值。头文件到目前为止是: typedef unsigned int uint; typedef std::initializer_list<std::initializer_list<double>> i_list; class Matrix

    1热度

    2回答

    可以说我有以下几点: struct Foo { Foo() : bar([&]{ doSomething();}) std::function<void(void)> bar; void doSomething(){}; } 而且可以说,一个线程调用经常一个Foo实例的杆件,而另一个线程自毁foo的实例。因为Foo的析构函数被首先调用,所以调用bar会导致无效

    1热度

    4回答

    class box { public: double length; double breadth; double height; ~box() { cout<<"destructor executed "<<"\n"; } }; int main(){ box mybox; mybox.~box(); ret