在这里遇到一些问题:
Waz位于名为Test
的DLL中Waz.h
// Import/Export Pattern
#ifdef TEST_EXPORTS
#define DllExport __declspec(dllexport)
#else
#define DllExport __declspec(dllimport)
#endif
#pragma once
#ifndef __Test__Waz__
#define __Test__Waz__
#include "WazImpl.h"
class DllExport Waz
{
/* Friends */
friend class WazImpl;
friend Waz operator*(const Waz &,const Waz &);
private:
WazImpl *p;
...
public:
...
};
#endif /* defined(__Test__Waz__) */
Waz operator*(const Waz &,const Waz &);
-------
Waz.cpp
(all def of the operator in public and ...)
Waz operator*(const Waz & w1, const Waz & w2)
{
Waz ww;
*ww.p=*w1.p * *w2.p;
return ww;
}
Then in the solution I have a console application and in my main
int main()
{
Waz a;
a(1,1) =3 ; // this line works fine operator() is defined in the public of the Waz class
Waz b;
Waz c = a*b; // ERROR
ERROR:
error LNK2019 : unresolved external symbol "class Waz __cdecl operator*(class Waz const &, class Waz const &)" (??D@YA?AVWaz@@ABV0@0@Z) referenced in the function _main
error LNK1120 : 1 unresolved external symbol
基于a(1,1)工作的事实,它意味着类的操作符被正确导出,问题只来自朋友操作员*! 任何的想法?不知道该怎么做才能解决这个问题.. 在此先感谢!!
答案 0 :(得分:0)
运算符在类外声明,只需将其导出:
DllExport Waz operator*(const Waz &,const Waz &);