乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 86|回复: 6

向导的arx自动生成的代码virtual中的不明白

[复制链接]

10

主题

46

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
86
发表于 2013-7-29 11:01:00 | 显示全部楼层 |阅读模式
  1. //-----------------------------------------------------------------------------
  2. //----- acrxEntryPoint.cpp
  3. //-----------------------------------------------------------------------------
  4. #include "StdAfx.h"
  5. #include "resource.h"
  6. #include
  7. //-----------------------------------------------------------------------------
  8. #define szRDS _RXST("hjkl_")
  9. //-----------------------------------------------------------------------------
  10. //----- ObjectARX EntryPoint
  11. class Carx1App : public AcRxArxApp {
  12. public:
  13.   Carx1App () : AcRxArxApp () {}
  14. //////////////////////////////////////下面的这行我不明白!
  15.   virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
  16.     // TODO: Load dependencies here
  17.     // You *must* call On_kInitAppMsg here
  18.     AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
  19.    
  20.     // TODO: Add your initialization code here
  21.     return (retCode) ;
  22.   }
  23.   virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
  24.     // TODO: Add your code here
  25.     // You *must* call On_kUnloadAppMsg here
  26.     AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
  27.     // TODO: Unload dependencies here
  28.     return (retCode) ;
  29.   }
  30.   virtual void RegisterServerComponents () {
  31.   }
  32.   // - hjkl_arx1.arx1 command (do not rename)
  33.   static void hjkl_arx1arx1(void)
  34.   {
  35.     // Add your code for command hjkl_arx1.arx1 here
  36.     acutPrintf(_T("你大爷的,你在搞什么呢?????????"));
  37.   }
  38.   // - hjkl_arx1.q9527 command (do not rename)
  39.   static void hjkl_arx1q9527(void)
  40.   {
  41.     // Add your code for command hjkl_arx1.q9527 here
  42.   }
  43. } ;
  44. //-----------------------------------------------------------------------------
  45. IMPLEMENT_ARX_ENTRYPOINT(Carx1App)
  46. ACED_ARXCOMMAND_ENTRY_AUTO(Carx1App, hjkl_arx1, arx1, 你大爷, ACRX_CMD_TRANSPARENT, NULL)
  47. ACED_ARXCOMMAND_ENTRY_AUTO(Carx1App, hjkl_arx1, q9527, g2, ACRX_CMD_TRANSPARENT, NULL)

问题来了:
//////////////////////////////////////下面的这行我不明白!
  virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt)
我看过的c++书籍,
都是virtual 后面跟一个函数,
而此处AcRx::AppRetCode 是一个函数,而On_kInitAppMsg 又是另外一个函数,让我不明白是什么意思!
求高手解答
回复

使用道具 举报

28

主题

56

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
168
发表于 2013-7-29 11:18:00 | 显示全部楼层
定义C++中虚函数的关键字
在使用virtual之前,C++对成员函数使用静态联编,而使用virtual,并且在调用函数时是通过指针或引用调用,
C++则对成员函数进行动态编联。
回复

使用道具 举报

10

主题

46

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
86
发表于 2013-7-29 11:23:00 | 显示全部楼层

我知道virtual的意思
回复

使用道具 举报

10

主题

46

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
86
发表于 2013-7-29 11:24:00 | 显示全部楼层
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt)
这句能和virtual    int     On_kInitAppMsg (void *pkt)
类比吗?
可是AcRx::AppRetCode 明显是类AcRx的构造函数AppRetCode呀
回复

使用道具 举报

2

主题

165

帖子

6

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
173
发表于 2013-7-30 13:56:00 | 显示全部楼层

AcRx是个struct,AppRetCode是个枚举变量(enum,是enumeration 的缩写),在C++中,有些时候为了代码更加具有可读性,引入这么个枚举变量,如 MyInt{First , Second, Third},这个First是MyInt::First,默认的值就是个int类型,值为0。 MyInt{First=1 , Second, Third},按上面的来讲,First就是1,而不是为0了。这是C++的内容。
virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt),这个函数就不难看懂了吧?
virtual关键字,表明是个虚函数。
AcRx::AppRetCode这个是枚举变量的内容,跟上面示例的MyInt是一个东西,也是下面函数的返回值内容,
On_***是函数名称。
如果还不明白,我就再说多点,On_***这个函数返回的,一定是AcRx::AppRetCode的东西,就是kRetOk或者kRetError。
ObjectARX中,还有很多类似的东西,用得最多的就是:Acad::ErrorStatus。
最后,附上完整的AcRx定义:
  1. struct AcRx {
  2.     typedef void (*FcnPtr) ();
  3.     enum         DictIterType { kDictSorted   = 0,
  4.                                 kDictCollated = 1 };
  5.     enum         Ordering     { kLessThan     = -1,
  6.                                 kEqual        = 0,
  7.                                 kGreaterThan  = 1,
  8.                                 kNotOrderable = 2 };
  9.     enum         AppMsgCode   { kNullMsg         = 0,
  10.                                 kInitAppMsg      = 1,
  11.                                 kUnloadAppMsg    = 2,
  12.                                 kLoadDwgMsg      = 3,
  13.                                 kUnloadDwgMsg    = 4,
  14.                                 kInvkSubrMsg     = 5,
  15.                                 kCfgMsg          = 6,
  16.                                 kEndMsg          = 7,
  17.                                 kQuitMsg         = 8,
  18.                                 kSaveMsg         = 9,
  19.                                 kDependencyMsg   = 10,
  20.                                 kNoDependencyMsg = 11,
  21.                                 kOleUnloadAppMsg = 12,
  22.                                 kPreQuitMsg      = 13,
  23.                                 kInitDialogMsg   = 14,
  24.                                 kEndDialogMsg    = 15,                                
  25.                                 kSuspendMsg      = 16 };                                
  26.         
  27.     enum        AppRetCode   { kRetOK          = 0,
  28.                                 kRetError       = 3 };
  29. };
回复

使用道具 举报

10

主题

46

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
86
发表于 2013-10-16 19:36:00 | 显示全部楼层
是rxdefx.h这个头文件里面,我自己找到了
回复

使用道具 举报

10

主题

46

帖子

5

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
86
发表于 2013-10-16 19:42:00 | 显示全部楼层
acadstrc.h这个里面包含了Acad::ErrorStatus这个说明
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-5 06:55 , Processed in 0.300326 second(s), 66 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表