Click here to Skip to main content
15,921,941 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionmfc42 in vista Pin
Tara1417-Nov-07 19:18
Tara1417-Nov-07 19:18 
AnswerRe: mfc42 in vista Pin
toxcct18-Nov-07 4:52
toxcct18-Nov-07 4:52 
AnswerRe: mfc42 in vista Pin
Paresh Chitte18-Nov-07 18:06
Paresh Chitte18-Nov-07 18:06 
QuestionClass template argment list Pin
Oliver12317-Nov-07 10:27
Oliver12317-Nov-07 10:27 
AnswerRe: Class template argment list Pin
Chris Losinger17-Nov-07 12:50
professionalChris Losinger17-Nov-07 12:50 
AnswerRe: Class template argment list Pin
Mark Salsbery17-Nov-07 13:12
Mark Salsbery17-Nov-07 13:12 
AnswerRe: Class template argment list Pin
Jheriko++17-Nov-07 16:22
Jheriko++17-Nov-07 16:22 
QuestionDeleting objects allocated in other objects [modified] Pin
codeprojecter_17-Nov-07 7:30
codeprojecter_17-Nov-07 7:30 
Hi,

I use a c++ class library.
All of the class are derived from one base class (ex 'CObject')
Some class's methods return a pointer(allocated using 'new') to class objects.
So i have to delete those objects. (its hard because of heavy usage of such classes/methods all over the code)
and i have a plan to delete all pointers when app close using a pointer array.

// File : cobject.h

std::vector <CObject*> vecObjPtr;

class CObject
{

CObject::CObject()
{
vecObjPtr.push_back(this);
}

};

// File : keyboard.h

class Keyboard: public CObject
{
Keys* getKeys()
{
return new Keys();
}
};

// File : keys.h

class Keys : public CObject
{
Key* getKey(int value)
{
return new Key(value);
}
};

// File : key.h

class Key : class CObject
{
Key(int value)
{
//...
}
};

#include <cobject.h>
#include ...
...

void main()
{

Keyboard *keybrd = new Keyboard();
Key *key = keybrd->getKeys()->getKey(10);

// done

delete the pointer returned by getKeys,getKey and keybrd by
poping items from vecObjPtr and delete;

}

is it a right way to do or is there any standard way of freeing memory like this ?

thanks in advance




-- modified at 11:36 Sunday 18th November, 2007
AnswerRe: Deleting objects allocated in other objects Pin
Jheriko++17-Nov-07 16:37
Jheriko++17-Nov-07 16:37 
GeneralRe: Deleting objects allocated in other objects Pin
codeprojecter_18-Nov-07 5:48
codeprojecter_18-Nov-07 5:48 
GeneralRe: Deleting objects allocated in other objects Pin
Jheriko++18-Nov-07 9:47
Jheriko++18-Nov-07 9:47 
AnswerRe: Deleting objects allocated in other objects Pin
Gary R. Wheeler18-Nov-07 0:26
Gary R. Wheeler18-Nov-07 0:26 
GeneralRe: Deleting objects allocated in other objects Pin
codeprojecter_18-Nov-07 5:52
codeprojecter_18-Nov-07 5:52 
QuestionWorking area of non-primary screens. Pin
RichardM117-Nov-07 5:32
RichardM117-Nov-07 5:32 
AnswerRe: Working area of non-primary screens. Pin
Nelek18-Nov-07 22:15
protectorNelek18-Nov-07 22:15 
GeneralRe: Working area of non-primary screens. Pin
RichardM119-Nov-07 2:29
RichardM119-Nov-07 2:29 
GeneralRe: Working area of non-primary screens. Pin
Nelek19-Nov-07 21:43
protectorNelek19-Nov-07 21:43 
GeneralRe: Working area of non-primary screens. Pin
RichardM123-Nov-07 4:29
RichardM123-Nov-07 4:29 
QuestionFix the window position Pin
CJ94200217-Nov-07 1:35
CJ94200217-Nov-07 1:35 
QuestionRe: Fix the window position Pin
bob1697217-Nov-07 3:53
bob1697217-Nov-07 3:53 
QuestionAbout Socket Pin
manish.patel17-Nov-07 0:52
manish.patel17-Nov-07 0:52 
AnswerRe: About Socket Pin
Mark Salsbery17-Nov-07 5:46
Mark Salsbery17-Nov-07 5:46 
GeneralRe: About Socket Pin
led mike17-Nov-07 6:01
led mike17-Nov-07 6:01 
GeneralRe: About Socket Pin
Mark Salsbery17-Nov-07 6:06
Mark Salsbery17-Nov-07 6:06 
AnswerRe: About Socket Pin
Moak18-Nov-07 12:38
Moak18-Nov-07 12:38 

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.