Click here to Skip to main content
15,909,445 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: C++ Newbie question Pin
toxcct30-Jun-08 1:30
toxcct30-Jun-08 1:30 
AnswerRe: C++ Newbie question Pin
Saurabh.Garg30-Jun-08 0:17
Saurabh.Garg30-Jun-08 0:17 
GeneralRe: C++ Newbie question Pin
kaminem30-Jun-08 0:24
kaminem30-Jun-08 0:24 
GeneralRe: C++ Newbie question Pin
markkuk30-Jun-08 1:28
markkuk30-Jun-08 1:28 
Questionprint input parameter values Pin
George_George29-Jun-08 23:35
George_George29-Jun-08 23:35 
AnswerRe: print input parameter values Pin
Rajesh R Subramanian29-Jun-08 23:41
professionalRajesh R Subramanian29-Jun-08 23:41 
GeneralRe: print input parameter values Pin
George_George30-Jun-08 1:10
George_George30-Jun-08 1:10 
GeneralRe: print input parameter values Pin
Rajesh R Subramanian30-Jun-08 1:24
professionalRajesh R Subramanian30-Jun-08 1:24 
GeneralRe: print input parameter values Pin
George_George30-Jun-08 1:46
George_George30-Jun-08 1:46 
GeneralRe: print input parameter values Pin
Rajesh R Subramanian30-Jun-08 2:15
professionalRajesh R Subramanian30-Jun-08 2:15 
GeneralRe: print input parameter values Pin
George_George30-Jun-08 2:27
George_George30-Jun-08 2:27 
GeneralRe: print input parameter values Pin
Rajesh R Subramanian30-Jun-08 2:48
professionalRajesh R Subramanian30-Jun-08 2:48 
GeneralRe: print input parameter values Pin
George_George30-Jun-08 16:03
George_George30-Jun-08 16:03 
GeneralRe: print input parameter values Pin
Hamid_RT30-Jun-08 23:08
Hamid_RT30-Jun-08 23:08 
GeneralRe: print input parameter values Pin
George_George30-Jun-08 23:24
George_George30-Jun-08 23:24 
GeneralRe: print input parameter values Pin
Hamid_RT1-Jul-08 21:39
Hamid_RT1-Jul-08 21:39 
GeneralRe: print input parameter values Pin
George_George2-Jul-08 1:42
George_George2-Jul-08 1:42 
GeneralRe: print input parameter values Pin
Hamid_RT2-Jul-08 18:16
Hamid_RT2-Jul-08 18:16 
GeneralRe: print input parameter values Pin
George_George6-Jul-08 3:12
George_George6-Jul-08 3:12 
QuestionCheck file in use Pin
Karismatic29-Jun-08 23:28
Karismatic29-Jun-08 23:28 
AnswerRe: Check file in use Pin
SandipG 29-Jun-08 23:31
SandipG 29-Jun-08 23:31 
GeneralRe: Check file in use Pin
Saurabh.Garg29-Jun-08 23:37
Saurabh.Garg29-Jun-08 23:37 
GeneralRe: Check file in use Pin
Karismatic29-Jun-08 23:42
Karismatic29-Jun-08 23:42 
GeneralRe: Check file in use Pin
SandipG 30-Jun-08 0:14
SandipG 30-Jun-08 0:14 
QuestionFunction pointer corrupts the stack or heap Pin
BadKarma29-Jun-08 22:55
BadKarma29-Jun-08 22:55 
Hi,

I have encountered this really strange bug. For a new project I have split a old, working class and its member class into two single classes (functional, wrapper).
When I use the same code that has worked for years, it crashes with heap or stack corruption. I have narrowed the bug to the use of a function pointer in the wrapper class to a member of the functional class. When i add this pointer as a member of the wrapper class, the corruption happenes i don't even have to call it.
This is the code that does the woe.
int _tmain(int argc, _TCHAR* argv[])
{
  functional oFun;

  {
    // this is to use the scope effect
    wrapper wrap(&oFun);  
  }
  
  return 0;
}

When exiting the stack is corrupted.
The is the code of the wrapper class
--wrapper.h--
#pragma once
class functional;
class wrapper
{
public:
  wrapper(functional* pFun);
  ~wrapper(void);
  
  void (functional::*pExitFunction)();	// the addition of this line causes the corruption
                                        // even if you don't use it in the cpp side
  functional* _pFun;
};

--wrapper.cpp--
#include "wrapper.h"
#include "functional.h"
wrapper::wrapper(functional* pFun)
{
  _pFun = pFun;
  
  pExitFunction = &functional::set_one;
}
wrapper::~wrapper(void)
{
  (_pFun->*pExitFunction)();
}

This is the code of the functional class
--functional.h--
#pragma once

class functional
{
public:
  functional(void);
  ~functional(void);
  void set_one();
  int _iData;
};

--functional.cpp--
#include "functional.h"

functional::functional(void)
{
  _iData = 0;
}

functional::~functional(void)
{
}

void functional::set_one()
{
  _iData = 1;
}


Why does the stack get corrupted?
I'm really stuck on this one, so any pointers would help me a lot.

Learn from the mistakes of others, you may not live long enough to make them all yourself.

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.