gpt4 book ai didi

c++ - 实现纯虚方法后 vtable C++ 错误

转载 作者:行者123 更新时间:2023-11-30 03:40:29 39 4
gpt4 key购买 nike

我在类中定义了一个纯虚函数,如下所示:

   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 中的 objective-c 集成时遇到了上述错误。而在 C++ 中它工作正常

下面这一行导致了 ViewController.mm 中的错误:

RadioProximityParticleFilter *obj = new RadioProximityParticleFilter (*asList,50);

最佳答案

我完成了您的代码,以便在我的 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.

关于c++ - 实现纯虚方法后 vtable C++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37982367/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com