我在类中定义了一个纯虚函数,如下所示:
template <typename T>
class PositioningMethod {
public:
virtual ApproximatePosition *getPosition(std::list<T*> &observedRadioSignals) = 0;
};
并在ParticleFilter中实现它,如下所示:
class ParticleFilter:public PositioningMethod<T> {
public:
virtual ApproximatePosition *getPosition(std::list<T*> &observedRadioSignals) {
/*Some code and return*/
return ApproximatePosition::from(xxxx, xxxx, xxxx());
}
};
但是低于错误:
"ParticleFilter<KnownBluetoothBeacon<CartesianLocation>, RadioProximity<BluetoothBeacon>
>::getPosition(std::__1::list<RadioProximity<BluetoothBeacon>*, std::__1::allocator<RadioProximity<BluetoothBeacon>*> >&)", referenced from:
vtable for RadioProximityParticleFilter in lib.a(RadioProximityParticleFilter.o)
"ParticleFilter<KnownBluetoothBeacon<CartesianLocation>, RadioProximity<BluetoothBeacon>
>::ParticleFilter(std::__1::list<KnownBluetoothBeacon<CartesianLocation>, std::__1::allocator<KnownBluetoothBeacon<CartesianLocation> > >&, double)", referenced from:
RadioProximityParticleFilter::RadioProximityParticleFilter(std::__1::list<KnownBluetoothBeacon<CartesianLocation>, std::__1::allocator<KnownBluetoothBeacon<CartesianLocation> > >&, double) in lib.a(RadioProximityParticleFilter.o)
ld: symbol(s) not found for architecture arm64
我知道vtable错误通常发生在非实现的纯虚函数上,但在我的情况下它是相同的。知道我哪里错了吗?
注意: 在将我的C ++代码与iOS中的目标C集成时,我遇到的上述错误。虽然在C ++中它的工作正常
以下行导致ViewController.mm中的错误:
RadioProximityParticleFilter *obj = new RadioProximityParticleFilter (*asList,50);
答案 0 :(得分:2)
我已经完成了您的代码,以便在我的MS VS 2013测试项目中使用它,它只是有效 - 这里是完整列表:
#include <iostream>
#include <list>
using namespace std;
class ApproximatePosition
{
public:
static ApproximatePosition *from( int a, int b, int c)
{
cout << "from called." << endl;
return NULL;
}
};
class ListElem{};
template <typename T>
class PositioningMethod
{
public:
virtual ApproximatePosition *getPosition(std::list<T*> &observedRadioSignals) = 0;
};
template <typename T>
class ParticleFilter :public PositioningMethod<T>
{
public:
virtual ApproximatePosition *getPosition(std::list<T*> &observedRadioSignals)
{
/*dummy input and return*/
int a = 0, b = 0, c = 0;
cout << "getPosition called." << endl;
return ApproximatePosition::from( a, b, c );// xxxx, xxxx, xxxx());
}
};
int main()
{
PositioningMethod<ListElem> *pm = new ParticleFilter<ListElem>();
std::list<ListElem*> l;
pm->getPosition( l );
}
输出结果为:
getPosition called.
from called.