delete-operator Questions
2
Solved
C++03 Standard say's:
5.3.5 Delete
[...] In either alternative, if the value of the operand of delete is the null pointer the operation has no effect.[...]
char *p = nullptr;
delete p; //no effec...
Nordine asked 17/11, 2017 at 16:12
1
Solved
And if so, why does the following code give me the warning
note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined...
Utica asked 17/11, 2017 at 15:7
5
Solved
I found the following snippet in the C++03 Standard under 5.3.5 [expr.delete] p3:
In the first alternative (delete object), if the static type of the object to be deleted is different from its d...
Dissipated asked 30/5, 2011 at 2:35
1
Solved
4 classes in the following codes: A, B, C and D.
They all have a member operator new[].
Besides,
B has a constructor;
C has a destructor;
D has a member operator delete[].
The Parameter size ...
Cryptomeria asked 20/8, 2017 at 11:35
11
Solved
I have an class A which uses a heap memory allocation for one of its fields. Class A is instantiated and stored as a pointer field in another class (class B.
When I'm done with an object of class B...
Pears asked 24/3, 2009 at 14:30
6
Consider a simple program:
int main() {
int* ptr = nullptr;
delete ptr;
}
With GCC (7.2), there is a call instruction regarding to operator delete in the resulting program. With Clang and Int...
Melonie asked 15/8, 2017 at 9:1
3
Solved
I've written the below code which overloads the new and delete operators and throws an exception in the destructor.
When the exception is thrown, why is the code in the delete operator not execute...
Nutt asked 12/8, 2017 at 20:52
3
Solved
The C++ Reference page lists 8 class specific overloads for global new operators. Four of those were added for 2017 version of C++.
Class-specific allocation functions
void* T::operator new ( std...
Breccia asked 6/8, 2017 at 20:38
2
Solved
What happens, in the following code, if construction / destruction of some array element throws?
X* x = new X[10]; // (1)
delete[] x; // (2)
I know that memory leaks are prevented, but additiona...
Transcend asked 17/7, 2017 at 15:57
4
Solved
I have small piece of code:
#include <iostream>
using namespace std;
int main()
{
int *p = new int(10);
if(p != NULL)
{
cout<<"Deleted dynamic allocated memory"<<end...
Nomism asked 17/7, 2017 at 11:19
3
Solved
Why were the non-placement new expression and the delete expression implemented as language built-in instead of regular functions?
If we have...
a way of requesting/giving back memory to the OS
...
Laurentian asked 7/7, 2017 at 11:40
3
Solved
Previous header: "Must I replace global operators new and delete to change memory allocation strategy in third party code?"
Short story:
We need to replace memory allocation technique in third-par...
Caloric asked 4/5, 2013 at 19:14
13
Solved
I have written a simple, working tetris game with each block as an instance of a class singleblock.
class SingleBlock
{
public:
SingleBlock(int, int);
~SingleBlock();
int x;
int y;
SingleBl...
Briefs asked 18/12, 2009 at 20:20
2
Is it required for user-defined and class-specific delete operators to ignore nullptr as that operators from standard library do?
parallel discussion at google groups.
Matos asked 3/2, 2017 at 20:46
4
Solved
I was solving some programming exercise when I realised that I have a big misunderstanding about pointers. Please could someone explain the reason that this code causes a crash in C++.
#include &...
Gobetween asked 16/12, 2016 at 12:8
3
Solved
I have class Item which defines its own operator new and operator delete as follows:
class Item
{
public:
Item(const std::string &s):msg(s)
{
std::cout<<"Ctor: "<<msg<<std...
Wargo asked 21/11, 2016 at 9:50
10
Solved
Is it allowed to delete this; if the delete-statement is the last statement that will be executed on that instance of the class? Of course I'm sure that the object represented by the this-pointer i...
Auxin asked 30/6, 2010 at 15:45
1
Solved
In following example, b is a polymorphic pointer type whose static type is Base* and whose dynamic type is Derived*.
struct Base
{
virtual void f();
};
struct Derived : Base
{
};
int main()...
Personalism asked 22/9, 2016 at 7:14
1
Solved
Can someone explain the nature of this C++ compile error? I am dabbling in/learning about overloading the global operators new, delete, and their variants. I read a couple of articles on the subjec...
Locket asked 5/9, 2016 at 5:13
6
Solved
So I was reading some Stack Overflow answers about deleting pointer arguments particularly these ones(1,2), because I am building a function, that requires a pointer as an argument.
A simplified v...
Fernandafernande asked 24/8, 2016 at 13:29
1
Solved
I am writing a C++ program for an embedded device, and I want to compile it without libstdc++, exceptions, and dynamic memory allocation.
Example program:
#include <stdio.h>
class A
{
publ...
Parley asked 22/8, 2016 at 16:47
5
Solved
std::allocator is an abstraction over the underlying memory model, which wraps the functionality of calling new and delete. delete doesn't need a size though, but deallocate() requires it.
void...
Pigmy asked 4/8, 2016 at 15:28
2
Why does my MSVC12 compiler not like this?
#include <new>
class thing
{
public:
thing() {}
~thing() {}
static void operator delete(void* ptr) = delete;
};
int main()
{
int g;
void* p ...
Baleen asked 23/3, 2016 at 23:0
2
Solved
In my implementation of a linked-list, my helper function deleteNode(Node*) that deletes inner class Node instances is throwing a runtime error, by "triggering a breakpoint" in the Local Windows De...
Scopas asked 23/2, 2016 at 7:28
3
Solved
I read that delete[] can deallocate an array of objects. However it is not mentioned in any of the sources I've read that whether it is an error or undefined to supply an argument like delete[3].
...
Lupulin asked 11/2, 2016 at 12:6
© 2022 - 2024 — McMap. All rights reserved.