Linked Questions

51 votes
5 answers
84k views

I read that destructors need to be defined when we have pointer members and when we define a base class, but I am not sure if I completely understand. One of the things I am not sure about is whether ...
user3435009's user avatar
23 votes
9 answers
6k views

Say I've got a class where the sole data member is something like std::string or std::vector. Do I need to provide a Copy Constructor, Destructor and Assignment Operator?
jjerms's user avatar
  • 1,145
3 votes
4 answers
10k views

Possible Duplicate: What is The Rule of Three? How exactly does std::pair call destructors for its components? I am trying to add instances of a class to an std::map, but I am getting errors ...
cmo's user avatar
  • 4,154
6 votes
3 answers
6k views

Possible Duplicate: What is The Rule of Three? I have the a problem of the double freeing of memory in the following program. The debugger shows that the issue is in the push_back() function. ...
Alex's user avatar
  • 10.2k
11 votes
2 answers
8k views

In the following code when I add the the line which is specified with an arrow gives error: Error in `./a.out': double free or corruption (fasttop): 0x00000000007a7030 * Aborted (core dumped) The ...
Shibli's user avatar
  • 6,199
5 votes
3 answers
4k views

I have issues with my destructor in my c++ program.When I run the program and take the users input, it suddenly calls the destructor before the cout can even print inside the statement. Assume that ...
Brogrammer93's user avatar
1 vote
4 answers
2k views

Why exactly do we need copy constructors? I am studying C++ and I am not able to understand the need for copy constructors , as without using a copy constructor also, i was getting correct output. I ...
Siddhant's user avatar
  • 644
3 votes
5 answers
2k views

This is a general question that I've been asking for a while but couldn't get a clear answer to. Do I need to code a copy constructor for a class when all instance data fields in this class are ...
Ash's user avatar
  • 71
1 vote
5 answers
1k views

Use example in link, but change to use char * and vector: #include <vector> using namespace std; class Test{ char *myArray; public: Test(){ myArray = new char[10]; } ~...
user2847598's user avatar
  • 1,339
6 votes
1 answer
972 views

Possible Duplicate: What is The Rule of Three? When you require to define to your own assignment operator?
user963241's user avatar
  • 7,128
1 vote
3 answers
6k views

Possible Duplicate: What is The Rule of Three? Array(const Array &arraytoCopy) :size(arraytoCopy.size) { ptr=new int[size]; for(i=0;i<size;i++) ptr[i]=arraytoCopy.ptr[i]; } ...
munish's user avatar
  • 4,694
0 votes
3 answers
2k views

In my application I used to have a unique_ptr<parent> _member as a member of a custom class. The code worked fine. However when I recently tried to create another class that inherit from the ...
user2178705's user avatar
6 votes
3 answers
387 views

While designing a class that dynamically allocates memory I ran into the following problem regarding memory allocation. I was hoping that some of you might be able to point me in the right direction ...
pontus's user avatar
  • 63
0 votes
1 answer
3k views

So I am having to do this exercise for a course in Udemy and I finished it. But running in on my own machine in GDB I get the error above in the title. I tried checking the values of the pointers for ...
Zeor137's user avatar
  • 195
0 votes
1 answer
1k views

I'm facing a strange issue. I wrote a Parent abstract class (implementing a pure virtual test() method) and its Child class (implementing the test() method). class Parent { public : ...
user1527491's user avatar

15 30 50 per page
1
2 3 4 5
124