《windows程序设计》第六章P217页的"KEYVIEW1"程序后,我发现它有一个小错误。
   
  我原封不动的把随书光盘上的"KEYVIEW1"程序复制到硬盘中开始编译时,VC++出现错误提示:  
   
  --------------------Configuration:   keyview1   -   Win32   Debug--------------------  
  Compiling...  
  keyview1.cpp  
  E:\Myfiles\CPP\keyview1\keyview1.cpp(112)   :   error   C2440:   '='   :   cannot   convert   from   'void   *'   to   'struct   tagMSG   *'  
                  Conversion   from   'void*'   to   pointer   to   non-'void'   requires   an   explicit   cast  
  Error   executing   cl.exe.  
   
  keyview1.obj   -   1   error(s),   0   warning(s)  
   
  出错的语句是112行:  
   
  pmsg   =   malloc   (cLinesMax   *   sizeof   (MSG))   ;  
   
  猜出来的意思是:不能把"void   *"类型的指针转换成"struct   tagMSG   *"类型的指针。  
   
  原来malllc()函数在内存中分配空间后返回的指针是"void   *"型,直接将这个"void   *"类型的指针赋给pmsg是不正确的,必须要经过强制类型转换。  
   
  将112行稍作一下修改:  
   
  pmsg   =   (PMSG)malloc   (cLinesMax   *   sizeof   (MSG))   ;  
   
  结果就正确了。  

  谢谢这位仁兄:  sunshine的资料信息

 

相关文章:

  • 2021-08-10
  • 2021-11-04
  • 2021-05-29
  • 2021-09-14
  • 2022-12-23
  • 2021-09-24
  • 2021-07-24
  • 2021-11-13
猜你喜欢
  • 2021-10-24
  • 2022-02-11
  • 2021-10-28
  • 2021-12-19
  • 2021-11-19
  • 2021-08-30
  • 2021-09-04
相关资源
相似解决方案