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: