♣
cstring 类型的变量也有长度限制?
#include<iostream>
using namespace std;
typedef void*(temp)(void*,void*);
void main()
{
int add(int&,int&);
int a=6;
int b=9;
temp *function;
function=(temp*)add(a,a);
if(function!=null)
cout<<"地址找到"<<endl;
(*function)(&b,&b);
}
int add(int& a,int& b)
{
int c;
c=a+b;
return c;
}
//////////////////////////////////////////////
当调用(*function)(&b,&b);就出内存错误
请教一下
· 网友精彩回答:
#include<iostream>
using namespace std;
typedef int (*temp)(int& ,int &);
int add(int& a,int& b)
{
int c;
c=a+b;
return c;
}
int main()
{
int a=6;
int b=9;
temp function=&add;
int res1=(*function)(a,a);
cout<<res1<<endl;
if(function!=null)
cout<<"µøö·õòµ½"<<endl;
int res2=(*function)(b,b);
cout<<res2<<endl;
system("pause");
return 0;
}
#include<iostream>
using namespace std;
typedef int*(temp)(int&,int&);
void main()
{
int add(int &,int&);
int a=6;
int b=9;
temp *function;
function=(temp*)add;
if(function!=null)
cout<<"地址找到"<<endl;
(*function)(b,b);
}
int add(int& a,int& b)
{
int c;
c=a+b;
return c;
}
你应该改成这样,
function=(temp*)add(a,a);并不是得到add的地址,而是把add(a,a)得到的整数(也就是a+a的值)强制转换成了函数指针.
- 更多问题:
- · 100分问个关于网页和图片编程的问题
- · 找工作
- · 51单片机如何与计算机串口通信
- · 怎么控制两个insert语句执行?
- · 概念问题在线等
- · 急~
- · 局域网内,Serv-U服务器,一台下载是3M,二还下载还是3M,多于2台时才有所下降,但是自己写的软件为什么1对1也达不到3M呢?
- · 各位大侠:想做个类似3721的可嵌入在IE里的小程序,如何下手?
- · 如何获取模式对话框的标题双击事件?
- · DropDownList的SelectedItem.Text总为第一条的内容
- · 各位大侠:想做个类似3721的可嵌入在IE里的小程序,如何下手?
- · 各位大侠:想做个类似3721的可嵌入在IE里的小程序,如何下手?
- · 外观感觉
- · Borland要出售IDE了,Delphi的前途何在啊?
- · SetLocalVariable 是干什么用的
- · vb里的split,ubound在jsp里怎么处理

