delete-operator Questions

13

Solved

I always wondered why automatic setting of the pointer to NULL after delete is not part of the standard. If this gets taken care of then many of the crashes due to an invalid pointer would not occu...
Substation asked 1/4, 2009 at 7:48

2

Is the behaviour of this code defined? int* ptr = new int[10]; operator delete[] (ptr, 0); This code compiles fine and (on my machine) it seems nothing is happening. Is its the behaviour defined...
Celio asked 26/7, 2019 at 12:29

1

Solved

Many answers on this site mentions that delete() calls destructor. But the sample code below seems to call delete() inside the destructor. What is the correct usage of delete() when object is initi...

9

Solved

Is it safe to delete a NULL pointer? And is it a good coding style?

2

I have written a express index.js to simple crud operation in mongodb. the item is the params I can console.log as mongodb Id however, ObjectId buildin function giving me a an class constructor err...
Felicafelicdad asked 24/2, 2023 at 6:33

1

I'm trying to compile the following code (this is a minimal example), but I get a warning I can't figure out: #include <string> #include <variant> #include <vector> struct Bar { ...
Thankyou asked 4/2, 2023 at 21:9

4

Solved

I have discovered the classic new/delete mismatch error in our codebase as follows: char *foo = new char[10]; // do something delete foo; // instead of delete[] foo; Just how serious is this? ...
Nichollenicholls asked 11/2, 2012 at 8:0

2

I get segmentation fault exception on the next code: class A { public: A() {} virtual ~A(){} double m_d; }; class B : public A { public: B() {} virtual ~B(){} int x; }; int main() { A*...
Unswerving asked 22/11, 2022 at 19:7

4

Solved

I read this question, but it still doesn't make a lot of sense to me. It still sounds more like a sugarcoating feature. What's the difference between: class A { // public/private ? A (const A&a...
Singspiel asked 17/9, 2013 at 10:55

1

Solved

I wonder if this code is legal: delete new (operator new(1)) char; This code does the same thing, but doesn't use delete expression on a pointer obtained from placement new: void* p = operator new...

10

Solved

class my_class { ... my_class(my_class const &) = delete; ... }; What does = delete mean in that context? Are there any other "modifiers" (other than = 0 and = delete)?
Jobye asked 1/4, 2011 at 13:14

1

Solved

The following class (with virtual destructor) contains a templated operator delete: struct S { virtual ~S() {} template <typename... Args> void operator delete(void* ptr, Args... args); };...
Ulane asked 11/8, 2022 at 14:34

29

Solved

What is the difference between using the delete operator on the array element as opposed to using the Array.splice method? For example: myArray = ['a', 'b', 'c', 'd']; delete myArray[1]; // or ...

7

Solved

What is the difference between delete and delete[] operators in C++?
Unlearn asked 11/3, 2010 at 14:32

2

Solved

How do I call new operator with alignment? auto foo = new(std::align_val_t(32)) Foo; //? and then, how to delete it properly? delete(std::align_val_t(32), foo); //? If this is the right form ...
Speculate asked 25/12, 2018 at 12:2

3

Solved

Given the following fragments of code : class MyDialog : public QDialog { ... }; MyDialog::~MyDialog() { qInfo() << "~MyDialog()"; } and // scope begins MyDialog d; d.setAttribu...
Worsted asked 7/11, 2021 at 14:57

8

Solved

int main() { Employee *e = new Employee(); delete e; delete e; ... delete e; return 0; }
Arthralgia asked 30/4, 2010 at 18:12

12

Solved

Ignoring programming style and design, is it "safe" to call delete on a variable allocated on the stack? For example: int nAmount; delete &nAmount; or class sample { public: sample(); ...
Nero asked 14/1, 2009 at 3:41

1

I'm not sure if I understood "sized deallocation" correctly in C++. In C++14 the following signature was added to the global scope: void operator delete(void* ptr, std::size_t size) noexcept I'm...
Zenithal asked 16/10, 2017 at 16:44

1

Solved

C++20 introduced "destroying operator delete": new overloads of operator delete that take a tag-type std::destroying_delete_t parameter. What exactly is this and when is it useful?
Locker asked 19/5, 2021 at 1:26

9

Solved

I'm playing a little with memory dynamic allocation, but I don't get a point. When allocating some memory with the new statement, I'm supposed to be able to destroy the memory the pointer points to...
Rookie asked 19/7, 2010 at 10:55

1

Solved

C++20 has added destroying form of operator delete distinguished by the std::destroying_delete_t parameter. It causes delete expression to no longer destroy the object prior to invoking operator de...
Ruminate asked 6/3, 2021 at 23:46

3

Solved

From cppreference we can see several new overloads of new and delete, as well as new[] and delete[] were added. I can't find any examples of usage with the new aligned overloads, neither on cpprefe...
Autonomous asked 4/11, 2018 at 20:15

2

Solved

In a freestanding context (no standard libraries, e.g. in operating system development) using g++ the following phenomenon occurs: class Base { public: virtual ~Base() {} }; class Derived : publ...
Glottochronology asked 28/7, 2015 at 20:32

3

Solved

I have DynamoDB table structured like this A B C D 1 id1 foo hi 1 id2 var hello A is the partition key and B is the sort key. Let' say I only have the partition key and don't know the sort key ...
Federative asked 6/4, 2018 at 1:59

© 2022 - 2024 — McMap. All rights reserved.