delete-operator Questions
2
What happens if two libraries (dynamicaly linked) have their own globally overridden version of the new and the delete operators and they use their own memory management?
Is it generally wrong to ...
Imbibe asked 11/12, 2015 at 13:6
6
Solved
A C++ book I have been reading states that when a pointer is deleted using the delete operator the memory at the location it is pointing to is "freed" and it can be overwritten. It also s...
Comply asked 27/10, 2015 at 17:19
2
Solved
Code like this from one of my books for example:
class HasPtr {
public:
HasPtr(const HasPtr& h): ps(new std::string(*h.ps)), i(h.i) { }
HasPtr(const std::string &s = std::string()): ps(n...
Emolument asked 27/8, 2015 at 23:44
2
Solved
There is a conversion function operator void*() const in C++ stream classes. so that all stream objects can be implicitly converted to void*. During the interaction with programmers on SO they sugg...
Brockbrocken asked 23/8, 2015 at 16:38
6
Solved
#include <queue>
using namespace std;
class Test{
int *myArray;
public:
Test(){
myArray = new int[10];
}
~Test(){
delete[] myArray;
}
};
int main(){
queue<Test> q
Test t...
Screwy asked 28/12, 2012 at 2:21
1
Solved
So I'm used to memory management in C where free(pointer) will free up all space pointed to by pointer. Now I'm confusing myself when attempting to do something simple in C++.
If I have a 2D...
Spoliate asked 8/6, 2015 at 23:17
3
Solved
I have a Qlist full of objects created dynamically. Prior to terminating my program, I call myqlist.clear()
My question is: does this also delete (free) the objects which are contained in the list...
Blodget asked 27/1, 2014 at 16:35
4
Solved
I saw the code snippet as follows:
class UPNumber {
public:
UPNumber();
UPNumber(int initValue);
...
// pseudo-destructor (a const member function, because
// even const objects may be destr...
Telpher asked 28/2, 2011 at 23:8
3
Solved
Why can I do:
int i = *(new int (5));
and successfuly use i after it,
but when I'm trying:
delete &i;
I get a run time error:
Unhandled exception at 0x5ddccaf7 (msvcr100d.dll) in Test...
Blindage asked 22/12, 2014 at 18:10
1
Solved
I've been reading up on the ownership of Qwidgets and deleting them.
eg: http://qt-project.org/doc/qt-4.8/objecttrees.html
This says "You can also delete child objects yourself, and they will remo...
Presentment asked 8/11, 2014 at 12:32
4
When must I use delete?
For example, say I'm allocating two objects:
Fraction* f1 = new Fraction(user_input1, user_input2);
Fraction* f2 = new Fraction(user_input3, user_input4);
The next time I w...
Marigolda asked 2/11, 2014 at 2:24
8
I'm new to C++ and I'm wondering why I should even bother using new and delete? It can cause problems (memory leaks) and I don't get why I shouldn't just initialize a variable without the new opera...
Millsaps asked 17/10, 2014 at 10:40
2
Solved
In the C++03 Standard, I see:
5.3.5 Delete
2 If the operand has a class type, the operand is converted to a pointer type by calling the above-mentioned conversion function, and the converted opera...
Chouinard asked 15/8, 2014 at 15:44
3
Is there anything wrong when deleting an object like this in C++?
MyCls* c = new MyCls();
void* p = (void*)c;
delete (MyCls*)p;
Surround asked 16/7, 2014 at 5:18
2
Solved
After making a lot of changes to a project, I created an error that took me quite a while to track down.
I have a class which contains a dynamically allocated array. I then create a dynamic array ...
Bernardina asked 26/2, 2014 at 9:11
6
Solved
Does delete[] a, where a is dynamic-allocated array of pointers, execute delete for each pointer in array?
I suppose, it executes destructor for arrays with user-defined classes, but what's happen...
Weinhardt asked 12/2, 2014 at 15:17
2
Solved
I've been reading about the C++11 smart pointers in order to use them on my sources, the documentation I've been reading is the one on cppreference.com; while reading about the std::unique_ptr, on ...
Passport asked 6/2, 2014 at 14:48
4
Solved
What is the Time Complexity of the delete[] operator?
I mean how is it implemented - does it iterate over all the elements in the array and calls destructor for every element?
Does this op...
Salvatore asked 12/1, 2014 at 16:27
3
Solved
I'm working on a memory pool/memory allocator implementation and I am setting it up in a manor where only a special "Client" object type can draw from the pool.The client can either be constructed ...
Tiatiana asked 6/1, 2014 at 7:55
2
In the following code, why is the address held by pointer x changing after the delete? As I understand, the deletecall should free up allocated memory from heap, but it shouldn't change the pointer...
Surmullet asked 22/12, 2013 at 0:40
2
Solved
I'm well aware that in C++, what delete[] is to new[], delete is to new. This is not about C++ syntax. I am wondering about the reasons delete[] was defined as something distinct from the plain del...
Elephantine asked 21/11, 2013 at 17:2
5
Solved
So during a code review, a colleague of mine used a double* d = new double[foo]; and then called delete d. I told them that they should change it to delete [] d. And they stated that the compiler d...
Guilbert asked 21/11, 2013 at 16:42
2
Solved
C++
Much literature says const references cannot be used to modify their referents and const pointers cannot be used to modify their pointees.
Then, why can they be deleted?
const int& cirDy...
Commandeer asked 11/10, 2013 at 21:48
6
Solved
IP_ADAPTER_INFO *ptr=new IP_ADAPTER_INFO[100];
if I free using
delete ptr;
will it lead to memory leak, if not then why ?
This is disassembly code generated by VS2005
; delete ptr;
00...
Feces asked 12/10, 2009 at 8:27
6
Solved
In this SO question is stated that this construct prevents stack allocation of instance.
class FS_Only {
~FS_Only() = delete; // disallow stack allocation
};
My question is, how does it prevent...
Gnat asked 17/9, 2013 at 10:45
© 2022 - 2024 — McMap. All rights reserved.