我正在尝试进行以下实施:
基类标题:
#ifndef BASE_HH
#define BASE_HH
namespace base {
class Agent
{
public:
int loop () {return loopImpl();}
protected:
virtual int loopImpl() =0;
}
#endif
标题或派生类:
#ifndef DERIVED_HH
#define DERIVED_HH
#include <base/agent.hh>
namespace derived {
class Agent : public base::Agent
{
protected:
virtual int loopImpl();
}
#endif
派生类的源文件:
#include <derived/agent.hh>
int Agent::loopImpl()
{
return 0;
}
现在,当我在终端中编译它并测试它时,它可以工作。但是当我尝试在Matlab中编译一个创建Agent对象的S函数时,我得到以下错误:
Error using mex
/path/sfunction.cpp In function ‘void mdlStart(SimStruct*)’:
/path/sfunction.cpp:51:56: error: invalid new-expression of abstract class type ‘derived::Agent’
derived::Agent *agent = new derived::Agent ();
/derived_path/agent.hh:28:11: note: because the following virtual functions are pure within ‘derived::Agent’:
class Agent: public base::Agent
In file included from /derived_path/agent.hh:22:0, from /path/sfunction.cpp:13:
/base_path/agent.hh:54:21: note: virtual int base::Agent::loopImpl() virtual int loopImpl () =0;
所以似乎g ++ 4.9编译器无法找到派生成员函数......任何人都可以给我一些提示,说明为什么会这样做以及如何处理它?如上所述,当我编译一个类似的文件创建一个相同派生类的对象时,它可以工作。
感谢您的时间。