Compiler C2491 error when you try to define data members as dllimport functions

   日期:2024-12-26    作者:90iao 移动:http://mip.riyuangf.com/mobile/quote/56251.html

This article helps you resolve the compiler C2491 error that occurs when you try to define data members as functions.

Original product version:   Visual C++
Original KB number:   815647

You cannot apply the keyword to implement a function. For example, when you try to define data members (including static data members and functions) as functions, you receive the following compiler C2491 error message:

'identifier' : definition of dllimport function not allowed

You can only apply the keyword to declarations. You cannot apply the keyword to implement functions. The purpose of this keyword is to declare the implementation of a function by a DLL. Similarly, if you apply the keyword to a data member, you receive the initial data from a DLL. Therefore, you can't assign a value in your code initially.

You receive the compiler C2491 error when you try to compile the following code:


This behavior occurs because you defined the function implementation as . To avoid this compiler error, don't define the function, but instead declare the function as follows:


Similarly, you receive the compiler C2491 error when you try to compile the following code:


You receive this error message because you defined the data member as . To avoid this compiler error, don't define the data member, but instead declare the data member as follows:


特别提示:本信息由相关用户自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


举报收藏 0评论 0
0相关评论
相关最新动态
推荐最新动态
点击排行
{
网站首页  |  关于我们  |  联系方式  |  使用协议  |  隐私政策  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2020018471号