试图通过指针调用成员函数 [英] Trying to call a member function through a pointer

查看:83
本文介绍了试图通过指针调用成员函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过指向它的指针调用成员函数,并且不能完全正确地获得

语法。这个编译错误C2064,术语没有

求值为1参数的函数..这是

无法编译的最小代码:


类CTest {

void函数(char * param);

};


无效CTest :: function(char * param)

{

//用parm做点什么;

}


void(CTest :: * pFunction)(char * param);


int _tmain(int argc,_TCHAR * argv [])

{

char * value;


pFunction(value); // **** C2064

}


我无法弄清楚正确的语法。谁能帮我?谢谢!


布鲁斯。

I am trying to call a member function through a pointer to it and can''t get
the syntax exactly right. This compiles with an error C2064, term does not
evaluate to a function taking 1 argument.. Here is the smallest code that
will not compile:

class CTest {
void function( char* param );
};

void CTest::function( char* param )
{
// Do something with parm;
}

void ( CTest::*pFunction )( char* param );

int _tmain(int argc, _TCHAR* argv[])
{
char* value;

pFunction( value ); // **** C2064
}

I just can''t figure out the right syntax. Can anyone help me? Thanks!

Bruce.

推荐答案

布鲁斯。写道:
Bruce. wrote:

我试图通过指向它的指针调用成员函数和

不能正确地获得语法。
I am trying to call a member function through a pointer to it and
can''t get the syntax exactly right.



< http://www.parashift.com/c++-faq-lite/pointers-to-members.html>


Brian

<http://www.parashift.com/c++-faq-lite/pointers-to-members.html>

Brian




" Default User" < de *********** @ yahoo.comwrote in message

news:5d ************* @ mid.individual.net ...

"Default User" <de***********@yahoo.comwrote in message
news:5d*************@mid.individual.net...

布鲁斯。写道:
Bruce. wrote:

>我试图通过指向它的指针来调用成员函数,并且
不能正确地获得语法。
>I am trying to call a member function through a pointer to it and
can''t get the syntax exactly right.



< http://www.parashift.com/c++-faq-lite/pointers-to-members.html>


<http://www.parashift.com/c++-faq-lite/pointers-to-members.html>



我无法弄清楚如何更改我的代码进行编译。它说一个

成员函数是:


它的类型是int(Fred :: *)(char,float)。如果一个非静态成员函数

类Fred


这就是我声明它的方式。我做错了什么?

我需要做些什么不同的事情?


布鲁斯。

I can''t figure out from that how to change my code to compile. It say a
member function is:

Its type is "int (Fred::*)(char,float)" if a non-static member function of
class Fred

And that is exactly the way I have it declared. What am I doing wrong?
What do I need to do differently?

Bruce.


布鲁斯。写道:
Bruce. wrote:

" Default User" < de *********** @ yahoo.comwrote in message

news:5d ************* @ mid.individual.net ...
"Default User" <de***********@yahoo.comwrote in message
news:5d*************@mid.individual.net...

> Bruce。写道:
>Bruce. wrote:

>>我试图通过指向它的指针来调用成员函数,并且
无法正确地获得语法。
>>I am trying to call a member function through a pointer to it and
can''t get the syntax exactly right.


< http://www.parashift.com/c++-faq-lite/pointers-to-members.html>

<http://www.parashift.com/c++-faq-lite/pointers-to-members.html>



我无法弄清楚如何更改我的代码进行编译。它说一个

成员函数是:


它的类型是int(Fred :: *)(char,float)。如果一个非静态成员函数

类Fred


这就是我声明它的方式。我做错了什么?

我需要做些什么不同的事情?


I can''t figure out from that how to change my code to compile. It say a
member function is:

Its type is "int (Fred::*)(char,float)" if a non-static member function of
class Fred

And that is exactly the way I have it declared. What am I doing wrong?
What do I need to do differently?



没有上下文很难说出来!


啊,看看你原来的帖子,我看到你试图调用

成员函数而没有该类的实例来调用它。你好b / b
不能这样做。


-

Ian Collins。

Hard to tell without the context!

Ah, looking at your original post I see you are attempting to call the
member function without an instance of the class to call it on. You
can''t do that.

--
Ian Collins.


这篇关于试图通过指针调用成员函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆