[英]export overloaded operator of a class
I've created (in Qt and Mingwin the specified case), a class that has the following structure: 我已经创建了(在Qt和Mingwin中为指定的情况),该类具有以下结构:
#ifndef POINT2D_H
#define POINT2D_H
#include "Calculus_global.h"
#include <QtCore>
namespace Calculus
{
/** Class for definition of a point in 2D space */
class CALCULUSSHARED_EXPORT CartesianPoint2D
{
public:
//! Constructor
CartesianPoint2D();
//! Set x value
void setX(const qreal &qrX);
// ETC ETC ETC
};
} // namespace Calculus
///////////////////////////////////////////////////////////////////////////////
// RELATED NON-MEMBER OPERATORS //
///////////////////////////////////////////////////////////////////////////////
//! Addition operator
Calculus::CartesianPoint2D operator +(const Calculus::CartesianPoint2D &xAPoint, const Calculus::CartesianPoint2D &xBPoint);
//! Subtraction operator
Calculus::CartesianPoint2D operator -(const Calculus::CartesianPoint2D &xAPoint, const Calculus::CartesianPoint2D &xBPoint);
// And so on...
#endif // POINT2D_H
When I use this library, class methods works well. 当我使用该库时,类方法运行良好。 But when I want to use an operator, I got the undefined reference error, for example:
但是,当我想使用运算符时,出现了未定义的引用错误,例如:
path\sources\testcalculus.cpp:273: error: undefined reference to `operator+(Calculus::CartesianPoint2D const&, Calculus::CartesianPoint2D const&)'
What I must do to export also the overloaded operators and use them? 要导出还重载的运算符并使用它们,我必须做什么?
Thanks for your replies. 多谢您的回覆。
You have to use CALCULUSSHARED_EXPORT in your free functions (the operators in this case) too. 您还必须在免费功能(在这种情况下为运算符)中使用CALCULUSSHARED_EXPORT。 This (I think) is true only to Windows.
我认为这仅适用于Windows。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.