rule-of-three

Unusual destructor behaviour when copying over stack variables

I wrote a test to check whether destructors were called before an overwriting assignment on a stack variable, and I can't find any rational explanation for the results... This is my test (in Visual C++ 2008 Release mode): #include <iostream> class C { public: char* ptr; C(char p) { ptr = new char[100]; ptr[0] = p;} ~C() { std::cout ...

Storing objects in STL vector - minimal set of methods

Hello What is "minimal framework" (necessary methods) of object, which I will store in STL <vector>? For my assumptions: #include <vector> #include <cstring> using namespace std; class Doit { private: char *a; public: Doit(){a=(char*)malloc(10);} ~Doit(){free(a);} }; int main(){ vector<Doit> v(10);...

C++ Copy Constructor + Pointer Object

Hello, I'm trying to learn "big three" in C++.. I managed to do very simple program for "big three".. but I'm not sure how to use the object pointer.. The following is my first attempt. I have a doubt when I was writing this... Questions Is this the correct way to implement the default constructor? I'm not sure whether I need to h...