当前位置:首页 > 技术问答集
firefox

cstring 类型的变量也有长度限制?

 所属目录:asp.net   |   类型:技术问答   |   时间:2007-05-12
 问题:

#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);就出内存错误  
  请教一下

· 网友精彩回答:

发表者:sankt(做最好的自己)

#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<<"&micro;&oslash;&ouml;·&otilde;&ograve;&micro;&frac12;"<<endl;  
          int   res2=(*function)(b,b);  
          cout<<res2<<endl;  
          system("pause");  
          return   0;  
  }

发表者:junguo(junguo)

#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的值)强制转换成了函数指针.

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved