【问题标题】:Error when using a macro expansion for function declarations对函数声明使用宏扩展时出错
【发布时间】:2014-08-14 12:44:00
【问题描述】:

我正在尝试为共享库的延迟加载创建一个代理类。

该库的API函数之一是:

int AttachCWnd(CWnd* pControl);

所以,我创建了一个宏来轻松地声明和路由从代理类到库的调用:

class CLibProxy {
public:
  typedef int  (*tAttachCWnd)(CWnd*);
  tAttachCWnd m_fAttachCWnd;
};

#define DECL_ROUTE(name, ret, args) \
  ret CLibProxy::name args \
  { \
    if (m_hDLL) \
      return m_f##name (args); \
    return ret(); \
  }

DECL_ROUTE(AttachCWnd, int, (CWnd* pControl));

但是在 VS2010 上编译失败:

error C2275: 'CWnd' : illegal use of this type as an expression

谁能解释一下原因?

【问题讨论】:

标签: c++ windows dll macros loadlibrary


【解决方案1】:

嗯,明显的错误。调用 m_fAttachCWnd 不应包含类型声明,而应仅包含参数:

return m_fAttachCWnd (CWnd* pControl);

应该变成

return m_fAttachCWnd (pControl);

谢谢@chris。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-12
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多