Click here to Skip to main content
15,889,595 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: opaque pointer Pin
Maxwell Chen12-Mar-08 18:42
Maxwell Chen12-Mar-08 18:42 
GeneralRe: opaque pointer Pin
George_George12-Mar-08 18:49
George_George12-Mar-08 18:49 
GeneralRe: opaque pointer Pin
Maxwell Chen12-Mar-08 18:54
Maxwell Chen12-Mar-08 18:54 
GeneralRe: opaque pointer Pin
George_George12-Mar-08 18:56
George_George12-Mar-08 18:56 
GeneralRe: opaque pointer Pin
Eytukan13-Mar-08 7:03
Eytukan13-Mar-08 7:03 
AnswerRe: opaque pointer Pin
Maxwell Chen13-Mar-08 9:24
Maxwell Chen13-Mar-08 9:24 
GeneralRe: opaque pointer Pin
George_George13-Mar-08 15:14
George_George13-Mar-08 15:14 
GeneralRe: opaque pointer Pin
Eytukan13-Mar-08 16:06
Eytukan13-Mar-08 16:06 
That deals with just one case. But the article has not talked about the dangerous side of it. If you are have hard pointers like that, there's heck a lot of chances that you'll end up in memory leaks. If the program is 21 odd lines, then there's no problem. But in an application that has 40-50 thousand lines, if you are implementing hard pointers like this, that's it. It's an assured dissaster. I guess opaque pointers fit more better for the raw C guys and not C++. I'll give a little example here:
<br />
class MyApp<br />
{<br />
<br />
  MyGun* pmygun;<br />
  MyBomb* pBomb;<br />
  MyMissle* pMissile;<br />
.<br />
.<br />
.<br />
<br />
}<br />
MyApp()<br />
{<br />
   //Many of these pointers will not get initialized here.<br />
}<br />
<br />
LoadWeapon(Handle,Type)<br />
{<br />
  // Load few<br />
}<br />
<br />
UnloadWeapon(Handle,Type)<br />
{<br />
<br />
}<br />
<br />
<br />
~MyApp()<br />
{<br />
  // Here you have the burden to check if allll the weaopns have been unloaded. Forgetting it would shatter your desktop ;)<br />
}<br />

And sometime back my mate had such a pointer(pobj) in his MyAppclass, and in the destructor he kept calling pobj->release() without checking if it's been initialized or not. In most of the circumstances it got initialized and it went fine, but a tricky flow got thru these initializing conditions and when the destructor of the MyApp class got called, it crashed the application. This is just one example . I've seen a lot more like that.

I wish to suggest something called the smart-pointers.





OK,. what country just started work for the day ? The ASP.NET forum is flooded with retarded questions. -Christian Graus


Best wishes to Rexx[^]

GeneralRe: opaque pointer Pin
George_George13-Mar-08 16:32
George_George13-Mar-08 16:32 
GeneralRe: opaque pointer Pin
Maxwell Chen13-Mar-08 19:04
Maxwell Chen13-Mar-08 19:04 
GeneralRe: opaque pointer Pin
George_George13-Mar-08 14:50
George_George13-Mar-08 14:50 
GeneralRe: opaque pointer Pin
Maxwell Chen13-Mar-08 9:25
Maxwell Chen13-Mar-08 9:25 
GeneralRe: opaque pointer Pin
George_George13-Mar-08 14:57
George_George13-Mar-08 14:57 
GeneralRe: opaque pointer Pin
Maxwell Chen13-Mar-08 19:09
Maxwell Chen13-Mar-08 19:09 
AnswerRe: opaque pointer Pin
Maxwell Chen13-Mar-08 19:13
Maxwell Chen13-Mar-08 19:13 
GeneralRe: opaque pointer Pin
George_George13-Mar-08 19:21
George_George13-Mar-08 19:21 
Questionconstructor for POD types? Pin
George_George12-Mar-08 15:51
George_George12-Mar-08 15:51 
AnswerRe: constructor for POD types? Pin
Michael Dunn12-Mar-08 19:20
sitebuilderMichael Dunn12-Mar-08 19:20 
GeneralRe: constructor for POD types? Pin
George_George12-Mar-08 19:35
George_George12-Mar-08 19:35 
GeneralRe: constructor for POD types? Pin
Michael Dunn16-Mar-08 16:08
sitebuilderMichael Dunn16-Mar-08 16:08 
GeneralRe: constructor for POD types? Pin
George_George16-Mar-08 16:31
George_George16-Mar-08 16:31 
GeneralRe: constructor for POD types? Pin
Michael Dunn16-Mar-08 16:38
sitebuilderMichael Dunn16-Mar-08 16:38 
GeneralRe: constructor for POD types? Pin
George_George16-Mar-08 16:42
George_George16-Mar-08 16:42 
GeneralRe: constructor for POD types? Pin
Michael Dunn16-Mar-08 16:57
sitebuilderMichael Dunn16-Mar-08 16:57 
GeneralRe: constructor for POD types? Pin
George_George16-Mar-08 22:50
George_George16-Mar-08 22:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.