Can someone elaberate a little on virtual destructors. What happens when you don't use them ect. I skimmed over the tutorial section but couldnt find any information on them. I'm trying to understand what is really happening when using certain features.
Virtual destructors are not the default behaviors because by default functions are not virtual. I'm not sure what you were trying to get at by saying that, but I had the same reaction as firedraco.
Virtual destructors are not quite the same as other virtual functions. A more on point FAQ Lite link is this one:
virtual destructors allow you to polymorphically destroy objects. Without making the dtor virtual, attempting to destroy an object through a parent class's pointer could cause severe problems and/or memory leaks.
class Parent_A {
public:
~Parent_A() { cout << "~Parent_A\n"; }
};
class Child_A : public Parent_A {
public:
~Child_A() { cout << "~Child_A\n"; }
};
class Parent_B {
public:
virtual ~Parent_B() { cout << "~Parent_B\n"; }
};
class Child_B : public Parent_B {
public:
~Child_B() { cout << "~Child_B\n"; }
};
/*
Basically, 'A' classes have virtual dtors
'B' classes do not have virtual dtors
*/
int main()
{
Parent_A* a = new Child_A;
Parent_B* b = new Chlid_B;
// polymorphically destroy the objects
delete b; // calls ~Child_B, followed by ~Parent_B, as you'd expect
delete a; // only calls ~Parent_A! ~Child_A never called! object not properly destroyed!
}
Using inheritance, sometimes when you are poring over the subclass methods implementation, it make a call to it's parent. Without using an IDE help, you would think maybe it is calling another method within the subclass instead of it's parent isn't it ?
If you have lot's of such subclasses then you got problem visualizing the whole flow. I use Notepad++ but I believe IDE should help me out but I not IDE fan so go figure.
Using composition, you would see that object.method or object->method signature which is easy to identify isn't it ?
So when I say easier to debug, I am referring to tracing the flow of the code.
Debugging without an IDE is masochism. How do you even use a debugger? Can they even operate without an environment to connect to?
If you have lot's of such subclasses then you got problem visualizing the whole flow.
That's more of a design problem. If the design is good, you won't have any of these problems you're describing. It should be immediately clear what a function call is doing and where it's going. If it isn't, your code is sloppy and/or you need to add comments.
Using composition, you would see that object.method or object->method signature which is easy to identify isn't it ?
My question above was sincere, not rhetorical. How does it work? How can you set breakpoints, watches, etc if not from an IDE? I can't visualize it.
Agree totally. gdb is way too old-school and command line based.
For Java I uses Eclipse so I presume I can make it work for my C++ programs too :)
Days without IDE to do debugging is your good old trusted printf and cout isn't it ? But for multi-threading debugging is extremely tricky. I wonder how ppl debug multi-threaded C++ program.
How does it work? How can you set breakpoints, watches, etc if not from an IDE? I can't visualize it.
Basically you type "break" or whatever and a line number, function name, etc. When stepping through it generally shows the line you are on and 2 or 3 lines above/below it. I agree it's quite annoying.
Yes, gdb is actually quite popular. My current company uses it extensively. Most of us there use Emacs or Vi and a number of modified gdbs. No IDE is necessary although they might be nice to have.
Yes, gdb is actually quite popular. My current company uses it extensively. Most of us there use Emacs or Vi and a number of modified gdbs. No IDE is necessary although they might be nice to have.
Let me guess. The average age of your company developers is in the range 35-50 ?
Nowadays, free IDE is rampant and as much as I try to keep away, the GUI effects sway me over bit by bit. Ok not only the GUI but the graphical tools for set breakpoints, watch variables etc etc.
I maybe old but I am willing to adapt new things especially if it is free and good to use :P