Click here to Skip to main content
15,893,722 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to build QT application statically Pin
Marco Bertschi6-Jan-14 1:00
protectorMarco Bertschi6-Jan-14 1:00 
GeneralRe: How to build QT application statically Pin
Utheen6-Jan-14 2:09
Utheen6-Jan-14 2:09 
GeneralRe: How to build QT application statically Pin
Gisle Vanem6-Jan-14 21:34
Gisle Vanem6-Jan-14 21:34 
GeneralRe: How to build QT application statically Pin
Utheen7-Jan-14 17:41
Utheen7-Jan-14 17:41 
GeneralRe: How to build QT application statically Pin
Gisle Vanem7-Jan-14 22:57
Gisle Vanem7-Jan-14 22:57 
Question[SOLVED}stack vs. heap objects: how to destruct only heap ones? Pin
liquid_4-Jan-14 6:12
liquid_4-Jan-14 6:12 
AnswerRe: stack vs. heap objects Pin
Richard Andrew x644-Jan-14 7:16
professionalRichard Andrew x644-Jan-14 7:16 
GeneralRe: stack vs. heap objects Pin
liquid_4-Jan-14 11:28
liquid_4-Jan-14 11:28 
I think I've just found pretty good solution which, however, may not work well in multithreaded environment. Let's add a static variable bool heapcreated, a flag createdflag and overload operator new. That would look like this:
C++
class sometype
{
  protected:
    static bool heapcreated;
    bool createdflag;
  public:
    sometype()
    {
      createdflag = heapcreated;
      heapcreated = false;
    }
    bool IsHeapCreated()
    {
      return createdflag;
    }
    void *operator new(size_t n)
    {
      sometype *stp=::new sometype;

      heapcreated = true;
      return stp;
    }
  
class container
{
  public:
    container(sometype *itp)
    {
      item = itp;
    }
    ~container();
    {
      if (item->IsHeapCreated())
         delete item;
    }
  private:
    sometype *item;
};


The new destructor of container would behave different depending on mode of sometype creation. I've searched this solution to be used when you build a library and you do not want a caller to have to do an overhead work adding a flag parameter. If you had to make many calls to container constructor with pointers to sometype it would be slightly difficult to save somewhere the pointers and then delete them. Also, you should be able to pass a pointer to stack variable which must not be deleted explicitly.
It's a bit tricky but my simple test works.
GeneralRe: stack vs. heap objects Pin
Richard Andrew x644-Jan-14 13:34
professionalRichard Andrew x644-Jan-14 13:34 
Question[SOLVED] Toolbar style window Pin
Richard Andrew x643-Jan-14 3:09
professionalRichard Andrew x643-Jan-14 3:09 
QuestionDeleting Files Pin
BobInNJ2-Jan-14 8:25
BobInNJ2-Jan-14 8:25 
AnswerRe: Deleting Files Pin
Chris Losinger2-Jan-14 9:58
professionalChris Losinger2-Jan-14 9:58 
AnswerRe: Deleting Files Pin
David Crow3-Jan-14 4:24
David Crow3-Jan-14 4:24 
GeneralRe: Deleting Files Pin
BobInNJ6-Jan-14 3:55
BobInNJ6-Jan-14 3:55 
QuestionGet the mouse position Pin
Richard Andrew x6431-Dec-13 19:43
professionalRichard Andrew x6431-Dec-13 19:43 
AnswerRe: Get the mouse position Pin
Richard MacCutchan1-Jan-14 1:20
mveRichard MacCutchan1-Jan-14 1:20 
GeneralRe: Get the mouse position Pin
Richard Andrew x641-Jan-14 7:07
professionalRichard Andrew x641-Jan-14 7:07 
AnswerRe: Get the mouse position Pin
SandipG 2-Jan-14 0:46
SandipG 2-Jan-14 0:46 
GeneralRe: Get the mouse position Pin
Richard Andrew x642-Jan-14 5:12
professionalRichard Andrew x642-Jan-14 5:12 
GeneralRe: Get the mouse position Pin
Richard Andrew x642-Jan-14 16:31
professionalRichard Andrew x642-Jan-14 16:31 
Question[SOLVED] Cann't Show Picture using RGB Data Pin
Django_Untaken30-Dec-13 20:00
Django_Untaken30-Dec-13 20:00 
QuestionRe: Cann't Show Picture using RGB Data Pin
Richard MacCutchan30-Dec-13 22:57
mveRichard MacCutchan30-Dec-13 22:57 
AnswerRe: Cann't Show Picture using RGB Data Pin
Django_Untaken31-Dec-13 0:24
Django_Untaken31-Dec-13 0:24 
GeneralRe: Cann't Show Picture using RGB Data Pin
Jochen Arndt31-Dec-13 3:48
professionalJochen Arndt31-Dec-13 3:48 
AnswerRe: Cann't Show Picture using RGB Data Pin
Django_Untaken31-Dec-13 5:56
Django_Untaken31-Dec-13 5:56 

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.