我正在制作一个React应用程序,它使用dropbox中的Djinni来连接C++和Javascript。从Javascript到C++的调用工作得很好,但是现在我正在实现从C++到Java/ObjC的调用,我的C++技能也是如此。所以我被困在初始化类方法上。我是以Djinni提供的例子为基础的。AnotherClassMain是从Javascript到C++的访问点。
我想从runAProcess内部的processAImpl调用anotherClassMain方法。
但是我得到了错误字段类型'aEditing::ProcessAImpl‘是ProcesAImpl processA;in anotherClassMain.hpp行上的一个抽象类。
我如何访问这个初始化类processAImpl并从anotherClassMain调用runAProcess ??
// processA.hpp由djinni创建
#pragma once
#include <string>
namespace aEditing {
class ProcessA {
public:
virtual ~ProcessA() {}
virtual bool runThisProcess(const std::string & str) = 0;
};
} //processAImpl.hpp
#pragma once
#include "processA.hpp"
namespace aEditing {
class ProcessAImpl : public ProcessA {
public:
ProcessAImpl(const std::shared_ptr<ProcessA> & listener);
void runAProcess(const std::string aCommand);
private:
std::shared_ptr<ProcessA> aProcess;
};
}//processAImpl.cpp
#include "procesAImpl.hpp"
namespace aEditing {
ProcessAImpl::ProcessAImpl (const std::shared_ptr<ProcessA> & listener) {
this->aProcess = listener;
}
void ProcessAImpl::runAProcess(const std::string aCommand) {
this->aProcess->runThisProcess(aCommand);
}
}//另一个ClassMain.hpp
#pragma once
#include "includes.hpp"
#include "processAImpl.hpp"
namespace anotherProcessing {
class AnotherProcessingMain: public anotherProcessing::AnotherProcessing {
public:
AnotherProcessingMain();
string anotherProcessing(const std::string &Input, const std::string &output) override;
private:
ProcesAImpl processA;
};
}//另一种
#include "anotherClassMain.hpp"
namespace anotherProcessing {
shared_ptr<AnotherProcessing> AnotherProcessing::create() {
return make_shared<AnotherProcessingMain>();
}
AnotherProcessingMain::AnotherProcessingMain() {}
string AnotherProcessingMain::anotherProcessing(const std::string &Input, const std::string &output){
processA.runAProcess("testCommand"); //Trying to access this!
return "yeah";
}发布于 2018-12-06 10:33:39
我如何访问这个初始化类
processAImpl并从anotherClassMain调用runAProcess??
我想您是指实例化类processAImpl。
ProcessA是一个抽象类,因为它包含一个pure virtual函数。
从抽象类派生时,必须在派生类中实现该pure virtual函数。否则,您将无法实例化派生类。
因此,在派生类runThisProcess(const std::string & str)中实现(提供) processAImpl的定义。
发布于 2018-12-06 10:34:45
您缺少了基类纯虚拟方法bool runThisProcess(const std::string &)的声明。您的意思是void ProcessAImpl::runAProcess(const string)是实现吗?
名称和参数类型必须与完全匹配。
runThisProcess对runAProcessconst std::string &对const string您应该将要重写基类方法的子类中的方法标记为override (如果可以有孙辈类)或final (如果不能),这样编译器就可以更好地通知您这样的输入。
您还缺少了AnotherProcessingMain::processA的初始化。你需要这样的东西
AnotherProcessingMain::AnotherProcessingMain()
: processA(/* a const std::shared_ptr<ProcessA> & from somewhere */)
{}因为您为ProcessAImpl定义的唯一构造函数是一个const std::shared_ptr<ProcessA> &。
这是非常可疑的,您有ProcessAImpl有一个std::shared_ptr<ProcessA>成员。需要有一些类在它的runThisProcess成员中执行实际操作,而且它可能应该是ProcessAImpl。按照目前的情况,ProcessAImpl 什么也不做。你基本上得到了海龟一直往下走。
https://stackoverflow.com/questions/53649304
复制相似问题