Click here to Skip to main content
16,007,277 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMemory Allocation Issues -- EXEs and DLLs Pin
Peter Weyzen10-Oct-01 18:49
Peter Weyzen10-Oct-01 18:49 
GeneralRe: Memory Allocation Issues -- EXEs and DLLs Pin
Paolo Messina10-Oct-01 23:25
professionalPaolo Messina10-Oct-01 23:25 
GeneralHiGlobal variable in VC++ Pin
10-Oct-01 18:42
suss10-Oct-01 18:42 
QuestionHow to Create and access Excel files programatically without using ODBC Pin
KMilind10-Oct-01 18:17
KMilind10-Oct-01 18:17 
AnswerRe: How to Create and access Excel files programatically without using ODBC Pin
Christian Graus10-Oct-01 18:39
protectorChristian Graus10-Oct-01 18:39 
AnswerRe: How to Create and access Excel files programatically without using ODBC Pin
Youknowme10-Oct-01 19:42
Youknowme10-Oct-01 19:42 
AnswerRe: How to Create and access Excel files programatically without using ODBC Pin
Michael P Butler10-Oct-01 22:05
Michael P Butler10-Oct-01 22:05 
Generalsafety of 'delete this' Pin
Peter Weyzen10-Oct-01 17:09
Peter Weyzen10-Oct-01 17:09 
It's time for the experts to help out.

I have a situation where I need to guarantee that an object is created and deleted from the same point. Better said that if it is "new'd" in a DLL, the delete must happen there too. [the linkage of the new and delete must be from the same source]

Or created in the EXE and deleted there.

The twist of this -- is that these objects are being created, and then fed into a machine object, which will dispose them when done. After I create this object, and feed it to the machine, then I am done with it. The machine object will use it, and dispose of it when done.

So, here's an example:
class BaseObject
{

public:
virtual void DeleteThis() = 0;
virtual void DoSomething() = 0;
};

class MyClass : public BaseObject
{
static New();

MyClass();


virtual void DeleteThis();
virtual void DoSomething();
};


MyClass *MyClass::New()
{
return new MyClass();
}

MyClass::MyClass()
{
}

void MyClass::DeleteThis()
{
delete this;
}

void MyClass::DoSomething()
{
printf( "%s", "I did it" );
}


/// some code
...

MyClass pObj = MyClass::New();

pObj->DoSomething();

pObj->DeleteThis();
...


this works -- but the question of safety has come up -- and this sample forces the linkage of new and delete to reside in the same .OBJ file (does this make sense?).

Is "delete this" safe in this situation?
GeneralRe: safety of 'delete this' Pin
Tomasz Sowinski11-Oct-01 1:59
Tomasz Sowinski11-Oct-01 1:59 
GeneralRe: safety of 'delete this' Pin
Peter Weyzen11-Oct-01 6:50
Peter Weyzen11-Oct-01 6:50 
GeneralRe: safety of 'delete this' Pin
Tomasz Sowinski11-Oct-01 6:57
Tomasz Sowinski11-Oct-01 6:57 
GeneralWhich Control Pin
Michael Martin10-Oct-01 16:44
professionalMichael Martin10-Oct-01 16:44 
GeneralRe: Which Control Pin
Christian Graus10-Oct-01 16:53
protectorChristian Graus10-Oct-01 16:53 
GeneralRe: Which Control Pin
Tomasz Sowinski11-Oct-01 2:03
Tomasz Sowinski11-Oct-01 2:03 
QuestionHow to access data in the Excel document!!! Pin
Jeason Zhao10-Oct-01 15:37
Jeason Zhao10-Oct-01 15:37 
AnswerRe: How to access data in the Excel document!!! Pin
Michael P Butler10-Oct-01 22:06
Michael P Butler10-Oct-01 22:06 
GeneralRe: How to access data in the Excel document!!! Pin
Jeason Zhao11-Oct-01 15:55
Jeason Zhao11-Oct-01 15:55 
QuestionCan someone help me modify this article? Please, please, please, please, please, please, please, please, please, please, please, please, please. Pin
DanYELL10-Oct-01 15:18
DanYELL10-Oct-01 15:18 
AnswerRe: Can someone help me modify this article? Please, please, please, please, please, please, please, please, please, please, please, please, please. Pin
Peter Sjöström10-Oct-01 22:33
Peter Sjöström10-Oct-01 22:33 
GeneralMulticast Demo Pin
Matt Newman10-Oct-01 15:09
Matt Newman10-Oct-01 15:09 
QuestionSetting window pos behind desktop icons? Pin
10-Oct-01 14:30
suss10-Oct-01 14:30 
AnswerRe: Why do you need this kind of code? Pin
Masaaki Onishi10-Oct-01 15:09
Masaaki Onishi10-Oct-01 15:09 
GeneralRe: Why do you need this kind of code? Pin
11-Oct-01 7:43
suss11-Oct-01 7:43 
AnswerRe: Setting window pos behind desktop icons? Pin
Michael Dunn10-Oct-01 15:47
sitebuilderMichael Dunn10-Oct-01 15:47 
GeneralPlatform SDk problem Pin
Janssens Johan10-Oct-01 13:50
Janssens Johan10-Oct-01 13: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.