delete-operator Questions
1
Solved
Earlier today I asked a question that led to another one: When should I use =delete? I don't think there is a post dedicated solely to =delete on SO, so I looked it up in a book called "The C...
Inveracity asked 17/9, 2013 at 5:15
2
Solved
For deleting and an array of element we use delete[].
Is it possible to delete the pointers the way I am doing below?
ClassA* object = new ClassA();
ClassA* pointer1 = object;
ClassA* objec...
Cosmic asked 15/9, 2013 at 8:27
2
I can't figure out why I get error for the code below.
The instances of object A will be pushed into a vector (vectorA.push_back(A a)) continuously. So sometimes, vectorA needs to be reallocated; t...
Affinal asked 24/7, 2013 at 17:8
1
Solved
If the class A in unique_ptr<A> it's own destructor, is it necessary to declare a deleter to ensure that the unique pointer uses that destructor? The example I am thinking of is that A has a ...
Palaeography asked 24/7, 2013 at 7:21
6
Solved
I am writing a template class which internally manages an array of the given type. Like this:
template<typename T>
class Example {
// ...
private:
T* objects; // allocated in c'tor (array)...
Parapsychology asked 27/6, 2013 at 13:37
1
Solved
I've been getting heap corruption error on delete[] instruction. Project is worked on in VC++ 2008, its requirement (so please don't focus on that). Whole building process is working OK, but in run...
Roden asked 8/6, 2013 at 11:58
2
Solved
I defined:
A** mat = new A*[2];
but how can I delete it? With delete[] mat; or delete[] *mat;?
Chader asked 29/5, 2013 at 1:33
3
Solved
If I do
struct MyStruct { ~MyStruct() { } };
void *buffer = operator new(1024);
MyStruct *p = new(buffer) MyStruct();
// ...
delete p; // <---------- is this okay?
is the delete guaranteed t...
Ergocalciferol asked 23/5, 2013 at 23:57
4
Solved
According to N3290, std::unique_ptr accepts a deleter argument in its constructor.
However, I can't get that to work with Visual C++ 10.0 or MinGW g++ 4.4.1 in Windows, nor with g++ 4.6.1 in Ubunt...
Hoofbeat asked 25/11, 2011 at 21:39
7
Solved
Why should would one replace the default operator new and delete with a custom new and delete operators?
This is in continuation of Overloading new and delete in the immensely illuminating C++ FAQ:...
Denny asked 22/8, 2011 at 15:4
1
I am investigating the pros and cons between using class overloaded news and deletes vs placement news. By this I mean, either declaring every class I may wish to new and delete with their own oper...
Askwith asked 24/4, 2013 at 13:54
4
Solved
I need to create pointers of instances of a class, and the program do not know at compilation time how many pointers I will create.
For deletion, I was considering storing the pointers in a vector,...
Strongbox asked 11/4, 2013 at 7:10
15
Lets say I have a function like this:
int main()
{
char* str = new char[10];
for(int i=0;i<5;i++)
{
//Do stuff with str
}
delete[] str;
return 0;
}
Why would I need to delete str i...
Autarchy asked 18/3, 2013 at 22:24
3
Solved
Let's say I want to make a type that cannot be constructed (don't ask why).
struct Impossible
{
I could do it like this:
Impossible() = delete;
// disable automatically generated constructors...
Avictor asked 3/1, 2013 at 11:17
4
Solved
Why C++ hasn't placement delete that directly corresponds to the placement new, i.e. calls the destructor and calls appropriate placement delete operator?
For example:
MyType *p = new(arena) MyTy...
Stopcock asked 2/5, 2011 at 12:42
3
Solved
Is it possible to have a virtual delete operator? I'm not talking destructor, I mean the actual operator overload.
Minus the fact that it is (in most cases) a big bad idea to overload new and delet...
Josefajosefina asked 16/12, 2012 at 0:10
4
Solved
Possible Duplicate:
Is there any reason to check for a NULL pointer before deleting?
I know that The C++ language guarantees that delete p will do nothing if p is equal to NULL. But c...
Venerate asked 11/12, 2012 at 10:56
1
Solved
Just a quick question:
Do I need to delete a pointer if I haven't actually assigned a new value to it?
What I've done if created a pointer and then handed it a reference to something like so:
Pl...
Mcburney asked 4/12, 2012 at 18:15
3
Solved
Consider the following:
char* msg = new char[20];
msg[4] = '\0';
delete[] msg;
Did the delete[] msg deallocate all the 20 chars allocated for msg or just those up to the \0?
If it deallocat...
Tongue asked 3/12, 2012 at 17:25
1
Solved
#include <new>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
struct foo {};
inline void* operator new(size_t size, foo*) throw (std::bad_alloc)
{
std::cout ...
Haversine asked 21/11, 2012 at 23:46
8
Solved
Cosider the following code:
class Foo
{
Monster* monsters[6];
Foo()
{
for (int i = 0; i < 6; i++)
{
monsters[i] = new Monster();
}
}
virtual ~Foo();
}
What is the correct destructo...
Unkempt asked 11/5, 2010 at 20:28
6
Solved
Context: I'm trying to wrap my head around pointers, we just saw them a couple of weeks ago in school and while practicing today I ran into a silly? issue, it can be super straightforward to you bu...
Giveandtake asked 4/11, 2012 at 22:2
1
Solved
I have two blocks of code about new[] and delete[]:
1)
#include <string>
int main()
{
std::string *p = new std::string[0];
delete[] p;
return 0;
}
2) In this case, I merely change st...
Oro asked 31/10, 2012 at 13:17
7
Solved
I remember reading somewhere that it's neccessary for delete NULL to be a valid operation in C++, but I can't remeber the reason why it should be so. Would someone please remind me?
Clydeclydebank asked 22/9, 2012 at 6:22
4
Solved
What will happen if we will run delete widget for widget that is in layout? If this case was written in documentation, please give me the link (I didn't find).
Code example:
QLabel *l1 = new QLab...
Liven asked 18/8, 2012 at 15:59
© 2022 - 2024 — McMap. All rights reserved.