指针在C ++中的分配 [英] Pointers alllocation in C++

查看:74
本文介绍了指针在C ++中的分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 char *(*)(char *,char *)); 



我需要在c ++中分配这个指针,我不知道怎么做,任何人都可以向我解释一下这个感谢。



我尝试了什么:



i对此指针一无所知

解决方案

那里缺少一些东西。



char * 定义函数指针的返回类型。



(*)原样无效;如果你打算声明一个函数指针,你必须给它一个名字,例如(* function_name

此外,还有一个与其开口不匹配的结束支架。



例如:

  #include   <   iostream  >  
使用 namespace std;

char * func1( char * s1, char * s2){
return 在func1()\ n;
}

char * func2( char * s1,< span class =code-keyword> char * s2){
return 在func2()\ n;
}

int main(){
char *(* myfunc)( char *, char *);
myfunc = func1;
cout<< myfunc( );
myfunc = func2;
cout<< myfunc( );
return 0 ;
}



这会产生以下输出:

在func1()
在func2()





希望这会有所帮助。请。


另见 cdecl:C gibberish< =>英语 [ ^ ]。

char *(*)(char *, char *)); 


hi, i need to allocate this pointer in c++, i am not sure how to do it, can any one explain this to me thanks.

What I have tried:

i did not understand anything about this pointer

解决方案

There is something missing in there.

char * defines the return type of the function pointer.

(*) is invalid as is; if you intend to declare a function pointer, you have to give it a name, for example (*function_name)
Besides, there is a closing bracket which does not match its opening one.

For example:

#include <iostream>
using namespace std;

char * func1(char *s1, char *s2) {
   return "In func1()\n";
}

char * func2(char *s1, char *s2) {
   return "In func2()\n";
}

int main() {
   char * (*myfunc)(char *, char *);
   myfunc = func1;
   cout << myfunc("", "");
   myfunc = func2;
   cout << myfunc("", "");
   return 0;
}


This produces the following output:

In func1()
In func2()



Hope this helps. Kindly.


See also cdecl: C gibberish <=> English[^].


这篇关于指针在C ++中的分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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