Reputation: 99
Hi fellow programmers.
I'm having a weird problem and have absolutely no clue of what's going on.
So I'm making a small library with some base things like maths and a window class.
Now to the problem, in my vec2 class I want to return a reference to a object but I get this compile error "error C2059: syntax error: '__declspec(dllexport)'"
class vec2 {
public:
float x, y;
vec2(float x = 0, float y = 0) : x(x), y(y) { }
float FW_API length();
vec2 FW_API normalize();
float FW_API dot(vec2& v);
vec2& FW_API rotate(float angle);
vec2& FW_API translate(float x, float y);
vec2& FW_API translate(vec2& v);
vec2 FW_API operator+(vec2& v);
vec2 FW_API operator-(vec2& v);
vec2 FW_API operator*(vec2& v);
vec2 FW_API operator/(vec2& v);
void FW_API operator+=(vec2& v);
void FW_API operator-=(vec2& v);
void FW_API operator*=(vec2& v);
void FW_API operator/=(vec2& v);
};
FW_API
is defined to __declspec(dllexport)
.
If I remove the ampersands it compiles without issue, but not with them.
So is it even possible to do that when exporting the methods to a dll?
Upvotes: 0
Views: 919
Reputation: 11
Your issue is that the "&" needs to go on the other side of the declspec
:
Instead of:
vec2& FW_API rotate(float angle);
It should be:
vec2 FW_API & rotate(float angle);
Upvotes: 1
Reputation: 99
Solution
class FW_API vec2
Putting the __declspec(dllexport) on the entire class instead of individual methods.
Upvotes: 1