指针困境 [英] pointer woes
问题描述
我遇到了成员函数指针的问题。它看到给我
跟随错误
运行时检查失败#0 - ESP的值没有正确保存到
函数调用。
如果我使用朋友类声明,它似乎只会给我带来问题
Any buts?
代码跟随:
#include" rootclass.h"
int _tmain(int argc,_TCHAR * argv [])
{
CRootClass * testclass;
testclass = new CRootClass;
testclass-> TestFunction ();
删除测试类;
返回0;
}
类CStore
{
public:
CStore(void);
~CStore(void);
朋友类CRootClass;
typedef void(CRootClass :: * FunctionPtr)(void);
void PassPtr(FunctionPtr FPtr);
};
#include" .\store.h"
CStore :: CStore(无效)
{
}
CStore ::〜CStore(无效)
{
}
无效CStore :: PassPtr(FunctionPtr FPtr)
{
// ptr发生的事情
}
#include"。\ store.h"
class CRootClass
{
public:
CRootClass (void);
~CRootClass(void);
CStore * m_Store;
void TestFunction(void);
};
#include" .\rootclass.h"
CRootClass :: CRootClass(void)
{
m_Store = new CStore();
m_Store-> PassPtr(& CRootClass :: TestFunction);
}
CRootClass :: ~CRootClass(无效)
{
删除m_Store;
}
void CRootClass :: TestFunction(void)
{
//一些代码
}
Hi,
I am having trouble with a member function pointer. It sees to give me the
followign error
Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.
It only seems to give me problems if I use the friend class declaration
Any thoughs ?
Code Follows:
#include "rootclass.h"
int _tmain(int argc, _TCHAR* argv[])
{
CRootClass *testclass;
testclass = new CRootClass;
testclass->TestFunction();
delete testclass;
return 0;
}
class CStore
{
public:
CStore(void);
~CStore(void);
friend class CRootClass;
typedef void(CRootClass::*FunctionPtr)(void);
void PassPtr(FunctionPtr FPtr);
};
#include ".\store.h"
CStore::CStore(void)
{
}
CStore::~CStore(void)
{
}
void CStore::PassPtr(FunctionPtr FPtr)
{
//something happens with ptr
}
#include ".\store.h"
class CRootClass
{
public:
CRootClass(void);
~CRootClass(void);
CStore *m_Store;
void TestFunction(void);
};
#include ".\rootclass.h"
CRootClass::CRootClass(void)
{
m_Store = new CStore();
m_Store->PassPtr(&CRootClass::TestFunction );
}
CRootClass::~CRootClass(void)
{
delete m_Store;
}
void CRootClass::TestFunction(void)
{
//some code
}
推荐答案
On Sun,26 Feb 2006 16:18:34 GMT,Ant < KK ****** @ hotmail.com>写道:
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kk******@hotmail.com> wrote:
我遇到了成员函数指针的问题。它看到给我
跟随错误
运行时检查失败#0 - ESP的值没有在
函数调用中正确保存。
<如果我使用朋友类声明,它似乎只会给我带来问题
任何问题?
代码遵循:
Hi,
I am having trouble with a member function pointer. It sees to give me the
followign error
Run-Time Check Failure #0 - The value of ESP was not properly saved across a
function call.
It only seems to give me problems if I use the friend class declaration
Any thoughs ?
Code Follows:
>
[snip]
您的代码编译并运行正常,但它没有做任何事情。你需要向我们展示产生错误的代码。
(顺便说一下,请不要发布使用非标准宏的代码
和_tmain和TCHAR等扩展名。
-
Bob Hairgrove
没有********** @ Home.com
" Bob Hairgrove" <在***** @ bigfoot.com>在消息中写道
news:ei ******************************** @ 4ax.com ...
"Bob Hairgrove" <in*****@bigfoot.com> wrote in message
news:ei********************************@4ax.com...
On Sun,26 Feb 2006 16:18:34 GMT,Ant < KK ****** @ hotmail.com>写道:
On Sun, 26 Feb 2006 16:18:34 GMT, "Ant" <kk******@hotmail.com> wrote:
我遇到了成员函数指针的问题。它看到给我
跟随错误
运行时检查失败#0 - ESP的值没有在
函数调用中正确保存。
如果我使用朋友类声明它似乎只给我带来问题
任何问题?
代码遵循:
Hi,
I am having trouble with a member function pointer. It sees to give me the
followign error
Run-Time Check Failure #0 - The value of ESP was not properly saved across
a
function call.
It only seems to give me problems if I use the friend class declaration
Any thoughs ?
Code Follows:
>
[snip]
你的代码编译并运行正常,尽管它什么也没做。您需要向我们展示产生错误的代码。
(顺便说一句,请不要发布使用非标准宏的代码和_tmain和TCHAR等扩展名) 。
-
Bob Hairgrove
没有**** ******@Home.com
对TCHAR业务感到抱歉,没注意到。
有趣的是你说它运行正常,这是我的编译器停止的代码。我编译的
调试版本有一些运行时检查。看来
当我的根类传递一个指针时它会以某种方式破坏堆栈指针,
或者其他类似的东西。
使用Visual Studio 2003会产生此错误
运行时检查失败#0 - ESP的值未正确保存
a功能调用。这通常是调用一个函数声明
的结果,其中一个调用约定带有一个用
不同调用约定声明的函数指针。
程序''[3768] friendtest.exe:Native'已退出代码-2147483645
(0x80000003)。 (一个或多个参数无效)
我不确定为什么会发生这种情况,所有调用约定都是相同的
Sorry about the TCHAR business, didnt notice that .
Interesting you say it runs fine, this is the code my compiler stops on. The
debug version I compile has some run time checks. It would appear that the
when my root class passes a pointer it somehow corrupts the stack pointer,
or something along those lines.
Using Visual Studio 2003 it produces this error
"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention.
The program ''[3768] friendtest.exe: Native'' has exited with code -2147483645
(0x80000003)." (One or more arguments are invalid )
I am not sure why this happenes, all the calling conventions are the same
On Sun,26 2006年2月17:41:56 GMT,Ant < An ******** @ hotmail.com>
写道:
On Sun, 26 Feb 2006 17:41:56 GMT, "Ant" <An********@hotmail.com>
wrote:
有趣的你说它运行正常,这是代码我的编译器停止。我编译的
调试版本有一些运行时检查。看来,当我的根类传递指针时,它会以某种方式破坏堆栈指针,
或类似的东西。
使用Visual Studio 2003会产生此错误
运行时检查失败#0 - 在函数调用中没有正确保存ESP的值。这通常是使用一个调用约定调用一个函数声明
的结果,函数指针用一个不同的调用约定声明。
程序''[3768] friendtest。 exe:Native''已退出代码-2147483645
(0x80000003)。 (一个或多个参数无效)
我不确定为什么会发生这种情况,所有调用约定都相同
Interesting you say it runs fine, this is the code my compiler stops on. The
debug version I compile has some run time checks. It would appear that the
when my root class passes a pointer it somehow corrupts the stack pointer,
or something along those lines.
Using Visual Studio 2003 it produces this error
"Run-Time Check Failure #0 - The value of ESP was not properly saved across
a function call. This is usually a result of calling a function declared
with one calling convention with a function pointer declared with a
different calling convention.
The program ''[3768] friendtest.exe: Native'' has exited with code -2147483645
(0x80000003)." (One or more arguments are invalid )
I am not sure why this happenes, all the calling conventions are the same
这是代码我编译并运行(所有在一个文件而不是
不同的标题)。它基本上相当于你发布的b / b
代码。但是,我确实删除了(void)。比特,因为那不是
C ++,以及将_tmain改为main:
// test_store.cpp
class CStore
{
public:
CStore();
~CStore();
朋友类CRootClass;
typedef void(CRootClass :: * FunctionPtr)();
void PassPtr(FunctionPtr FPtr);
};
CStore :: CStore()
{
}
CStore ::〜CStore()
{
}
void CStore :: PassPtr(FunctionPtr FPtr)
{
// ptr发生了什么事情
}
类CRootClass
{
public:
CRootClass();
~CRootClass();
CStore * m_Store;
void TestFunction();
};
CRootClass :: CRootClass()
{
m_Store = new CStore();
m_Store-> PassPtr(& CRootClass :: TestFunction);
}
CRootClass :: ~CRootC lass()
{
删除m_Store;
}
void CRootClass :: TestFunction( )
{
//一些代码
}
int main()
{
CRootClass * testclass;
testclass = new CRootClass;
testclass-> TestFunction();
删除测试类;
返回0;
}
-
Bob Hairgrove
否********** @ Home.com
这篇关于指针困境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!