![]() |
| | #16 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
|
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #17 |
| Hail to the king, baby. Join Date: Oct 2008 Location: Faroe Islands
Posts: 713
| Well, I dunno exactly what virtual means, but it doesn't change anything serious, if placed wrong, right? |
| Akkernight is online now | |
| | #18 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,099
| Best read up about inheritance, polymorphism and virtual functions, as well as abstract base classes (pure virtual functions). Not using virtual correct can mean overhead and headaches. Also, while deriving classes will "inherit" the virtual status of functions (including destructors), it is good practice, methinks, to actually mark them as virtual anyway, because it may not be obvious they are virtual unless you take a look at the base class and it doesn't hurt to put virtual in there anyway.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
Last edited by Elysia; 02-21-2009 at 06:26 AM. | |
| Elysia is offline | |
| | #19 |
| Registered User Join Date: Jan 2008
Posts: 575
| Yes, it will. Despite what has been offered, you only need a virtual destructor if you are going to destroy an object polymorphically. (If you religiously use good smart pointers, it is really a non-issue, but still, rather safe than sorry.) However, if you get this wrong, you destroy the universe. Consequently, if you already have one virtual method, marking the destructor as virtual will save you a headache and probably cost you only a little overhead--probably only measurable in hundreds of thousands of iterations or tens of bytes. By the by, it is always the "handle" class that needs a virtual destructor. (Where the "handle" class is whatever type you will store a pointer to for the sake of polymorphic destruction.) The destructor for classes that inherit from the "handle" class do not need to be marked 'virtual'. Soma Last edited by phantomotap; 02-21-2009 at 06:25 AM. |
| phantomotap is offline | |
![]() |
| Tags |
| classes, pointer |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Q: Pointers to Classes '->' notation | Howie17 | C++ Programming | 2 | 12-12-2008 10:09 AM |
| destructors and parameters + pointers to classes questions. | Zigs | C++ Programming | 12 | 12-31-2007 06:59 AM |
| two-dimensional dynamic array of pointers to classes | Timo002 | C++ Programming | 4 | 04-21-2005 06:18 AM |
| Pointers to Classes || pointers to structures | C++Child | C++ Programming | 24 | 07-30-2004 06:14 PM |
| Help With pointers in classes. | indigo0086 | C++ Programming | 12 | 10-10-2002 02:03 PM |