Click here to Skip to main content
15,903,030 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Text exchange VB 16 bit / VC 32 Pin
Dihirk6-May-06 22:55
Dihirk6-May-06 22:55 
GeneralRe: Text exchange VB 16 bit / VC 32 Pin
Dihirk7-May-06 2:47
Dihirk7-May-06 2:47 
GeneralRe: Text exchange VB 16 bit / VC 32 Pin
Maxwell Chen7-May-06 2:53
Maxwell Chen7-May-06 2:53 
GeneralRe: Text exchange VB 16 bit / VC 32 Pin
Dihirk7-May-06 3:11
Dihirk7-May-06 3:11 
QuestionClass Bascis Question... Pin
HakunaMatada6-May-06 1:55
HakunaMatada6-May-06 1:55 
AnswerRe: Class Bascis Question... Pin
Cedric Moonen6-May-06 2:03
Cedric Moonen6-May-06 2:03 
GeneralRe: Class Bascis Question... Pin
Stephen Hewitt6-May-06 2:44
Stephen Hewitt6-May-06 2:44 
AnswerRe: Class Bascis Question... Pin
Stephen Hewitt6-May-06 2:34
Stephen Hewitt6-May-06 2:34 
TechyMaila wrote:
CTest1 c ;
c.Hello() ;

With this technique the object is on the stack. If the object is very large you might not want to put it on the stack - However it is fairly rare for an object to be so big that it comes into the decision process. The main reason you use new to create an object is when you want to control its life time explicitly. For example, if you have an object on the stack and use it like this you're in for problems:
CTest1& Voodoo()
{
    CTest1 c;
    // Stuff goes here.
    return c; // Bad code!!!
}


This is because the object c is destroyed when its scope is exited; in this case when we exit the function the object is destroyed and no longer exists. Thus returning a reference to it is a disastrous mistake.

If you recode the example like this however there is no such problem but you are now responsible for controlling to object's life time:
CTest1* Voodoo()
{
    CTest1 *pObject = new CTest1;
    // Stuff goes here.
    return pObject;
}


The programmer must remeber to call delete on the object returned!

Steve
GeneralRe: Class Bascis Question... Pin
HakunaMatada6-May-06 2:51
HakunaMatada6-May-06 2:51 
GeneralRe: Class Bascis Question... Pin
Stephen Hewitt6-May-06 2:55
Stephen Hewitt6-May-06 2:55 
GeneralRe: Class Bascis Question... Pin
led mike6-May-06 6:11
led mike6-May-06 6:11 
AnswerRe: Class Bascis Question... Pin
Maxwell Chen6-May-06 3:31
Maxwell Chen6-May-06 3:31 
GeneralRe: Class Bascis Question... Pin
Stephen Hewitt6-May-06 3:54
Stephen Hewitt6-May-06 3:54 
GeneralRe: Class Bascis Question... Pin
Axter6-May-06 16:43
professionalAxter6-May-06 16:43 
GeneralRe: Class Bascis Question... Pin
Stephen Hewitt6-May-06 18:32
Stephen Hewitt6-May-06 18:32 
GeneralRe: Class Bascis Question... Pin
Maxwell Chen6-May-06 19:16
Maxwell Chen6-May-06 19:16 
GeneralRe: Class Bascis Question... Pin
Phil C6-May-06 20:12
Phil C6-May-06 20:12 
AnswerRe: Class Bascis Question... Pin
Maxwell Chen6-May-06 20:44
Maxwell Chen6-May-06 20:44 
GeneralRe: Class Bascis Question... Pin
Axter7-May-06 1:05
professionalAxter7-May-06 1:05 
GeneralRe: Class Bascis Question... Pin
Maxwell Chen7-May-06 2:02
Maxwell Chen7-May-06 2:02 
GeneralRe: Class Bascis Question... Pin
Axter7-May-06 5:53
professionalAxter7-May-06 5:53 
GeneralRe: Class Bascis Question... Pin
Maxwell Chen7-May-06 6:22
Maxwell Chen7-May-06 6:22 
GeneralRe: Class Bascis Question... Pin
Axter7-May-06 1:20
professionalAxter7-May-06 1:20 
QuestionRe: Class Bascis Question... Pin
Maxwell Chen7-May-06 2:08
Maxwell Chen7-May-06 2:08 
AnswerRe: Class Bascis Question... Pin
Axter7-May-06 5:57
professionalAxter7-May-06 5:57 

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.