2017-11-14 10 views
0

まず私はまだDLLの概念を受け入れ、今私は自分自身のための1つを作るためにしようとしているが、私は構築しようとすると、私はこれを取得:ビルドDLLエラー

error C2059: syntax error: '__declspec(dllimport)' 
error C2238: unexpected token(s) preceding ';' 
error C2059: syntax error: '__declspec(dllimport)' 
error C2238: unexpected token(s) preceding ';' 

Vec2.h:

#pragma once 

#ifdef VECTORLIB_EXPORTS 
#define VECTORLIB_API __declspec(dllexport) 
#else 
#define VECTORLIB_API __declspec(dllimport) 
#endif 

class Vec2 
{ 
public: 
    Vec2() = default; 
    VECTORLIB_API Vec2(double x, double y); 
    Vec2 VECTORLIB_API operator+(Vec2& rhs); 
    Vec2 VECTORLIB_API operator*(double& rhs); 
    Vec2& VECTORLIB_API operator+=(Vec2& rhs); 
    Vec2& VECTORLIB_API operator*=(double& rhs); 


public: 
    //public vars/////// 
    double x, y; 
    //////////////////// 
}; 

stdafx.hを:

// stdafx.h : include file for standard system include files, 
// or project specific include files that are used frequently, but 
// are changed infrequently 
// 

#pragma once 

#include "targetver.h" 

#define WIN32_LEAN_AND_MEAN// Exclude rarely-used stuff from Windows headers    
// Windows Header Files: 
#include <windows.h> 

#include "Vec2.h" 


// TODO: reference additional headers your program requires here 

Vector2.cpp:

// Vector2.cpp : Defines the exported functions for the DLL application. 
// 

#include "stdafx.h" 


Vec2::Vec2(double x, double y) : x(x), y(y) {} 

Vec2 Vec2::operator+(Vec2& rhs) 
{ 
    return Vec2(x + rhs.x, y + rhs.y); 
} 


Vec2 Vec2::operator*(double& rhs) 
{ 
    return Vec2(x * rhs, y * rhs); 
} 


Vec2& Vec2::operator+=(Vec2& rhs) 
{ 
    return (*this = *this + rhs); 
} 

Vec2& Vec2::operator*=(double& rhs) 
{ 
    return (*this = *this * rhs); 
} 

dllは、後で使用するvector2dクラスの開始点です。 私はこのコードがおそらくそうではないことを理解していますが、これらのコンセプトにぶつかり始めているので、ヒントは大歓迎です。

+0

Microsoft C++コンパイラを使用していますか?どのバージョン?ほとんどすべてのC++コンパイラはDLLを作成することをサポートしますが、関連するキーワードはMicrosoftとIntel vs g ++の間で少​​し異なります。 –

答えて

1

置き戻り値の型の前にVECTORLIB_APIhere

VECTORLIB_API Vec2 operator+(Vec2& rhs); 

また、クラスに追加することもできます。 here

class VECTORLIB_API Vec2 { 
    ... 
}; 
関連する問題