返回派生类函数的基类映射

时间:2016-05-16 21:00:28

标签: c++ dictionary inheritance return

我的C ++非常生疏,我需要一点复习。我有一个名为awk的抽象类,如下所示:

IReaderFactory

然后我有一个派生类,如下所示:

class IReaderFactory
{
public:

    virtual std::map<t_ReaderID, IReader> GetReaders() = 0;
    virtual void FreeReaders() = 0;
};

class DerivedFactory : IReaderFactory { public: std::map<t_ReaderID, IReader> GetReaders(); void FreeReaders(); private: std::map<t_ReaderID, DerivedReader> m_readers; LPDerived_DEVICE* devices; LPDerived_READER* readers; bool areReadersOpen = false; }; 功能的实现如下

GetReaders

请注意std::map<t_ReaderID, IReader> DerivedFactory::GetReaders() { int numDevices = 0, numReaders = 0; numDevices = Derived_DiscoverDevices(&devices); numReaders = Derived_DiscoverReaders(devices, numDevices, &readers); for (int i = 0; i < numReaders; ++i) { t_ReaderID ID = reinterpret_cast<char *>(readers[i]->id->id); DerivedReader o_Reader = DerivedReader(readers[i]); m_readers.insert(std::pair <t_ReaderID, DerivedReader>(ID, o_Reader)); std::cout << ID << std::endl; } areReadersOpen = true; return m_readers; } 继承自DerivedReader

我的编译器发出以下错误: IReader

我想在IntelliSense: no suitable user-defined conversion from "std::map<t_ReaderID, DerivedReader, std::less<t_ReaderID>, std::allocator<std::pair<const t_ReaderID, DerivedReader>>>" to "std::map<t_ReaderID, IReader, std::less<t_ReaderID>, std::allocator<std::pair<const t_ReaderID, IReader>>>" exists内将DerivedReader作为IReader返回,但不允许我这样做。任何帮助,将不胜感激。

修改 更新了使用std::map(Boost)

的代码
shared_ptr<IReader>

0 个答案:

没有答案