Search code examples
c++dllvisual-studio-2015dllexport

Return reference to object in DLL


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?


Solution

  • Solution

    class FW_API vec2

    Putting the __declspec(dllexport) on the entire class instead of individual methods.