如何定义函数在库中
How to define the function out side the Library?
我们有一些动态插件dll,这些插件是通过单独的保护生成的,并且在启动软件时使用。插件dll代码使用主项目中的一些标头文件。在编译插件代码时,如果主要项目标头文件包含某些功能和类别的定义,那么当时我会遇到错误,例如未解决的外部符号。
由于插件代码未找到(主项目(函数的定义,因此期望此错误。
注意:插件必须在主项目编译之前进行编译。
在两个情况下,插入代码已编译。1(如果主项目标头文件具有纯虚拟函数,那么它就是工作 完美(插头代码编译正常(。2(如果我要在类中编写函数定义。
我尝试了内联函数,但它不起作用。
---------------------
*** Main Project ***
---------------------
->This project generate .exe file
mainProject.h
-------------
class MainProjectHeder{
virtual void foo() = 0; // this function is work
void foo1(); // this function giving me error like unresolved external symbol
void foo2{ // this work
print("hello");
};
};
void MainProjectHeder::foo1(){
print("function not working");
}
ExperimentFactoryInterface.h
----------------------------
#include <MainProjectHeder.h>
class ExperimentFactoryInterface {
public:
virtual ~ExperimentFactoryInterface() {}
virtual MainProjectHeder* CreateExperiment(const QVariant& = QVariant()) = 0;
};
----------------------
*** Pulgin code ***
----------------------
->This Project is generate DLL file
Experiment.h
-------------
#include <mainProject.h>
class Experiment : public MainProjectHeder{
virtual void foo();
};
void Experiment:foo(){
print("work fine");
}
Factory.h
----------
#include "cyclicvoltammetry.h"
#include <ExperimentFactoryInterface.h>
class Factory : public ExperimentFactoryInterface {
public:
MainProjectHeder* CreateExperiment(const QVariant& = QVariant());
};
MainProjectHeder* Factory::CreateExperiment(const QVariant&) {
return new Experiment;
}
编译插件代码时;如何将函数定义void foo1();
的定义告知编译器,在项目或另一个项目中写出一边?
类的成员函数是一个函数,它在类定义中具有其定义或原型,就像任何其他变量一样。它在其是成员的类的任何对象上运行,并且可以访问该对象的所有类成员。
相关文章:
- 不同翻译单元中不可重载的非内联函数定义
- Visual Studio中的函数声明和函数定义问题
- 编写代码时C++出现错误:错误 1 错误 C2601:'circle':本地函数定义是非法的
- 具有enable_if外部类原型的模板类构造函数定义
- 类的前向声明之后的类成员函数定义,在类声明之前
- 为函数定义符号不明确的指针参数
- C++模板专用化 - 无法匹配函数定义
- 错误:在第 6 行'{'标记之前,此处不允许使用函数定义
- 找不到 #define 的函数定义
- 根据类型特征更改函数定义?
- 将抽象基类中的所有纯虚函数定义为 varaidaic 模板
- 命名空间更改函数定义
- "Type&"与C++函数定义中的"Type*"
- C++:为什么允许在另一个函数中声明函数,而不允许在函数定义中声明?
- 如何从 C++ 中的现有模板函数定义新函数
- 私有在函数定义/实现的返回值范围内是什么意思 (c++)?
- 越界成员函数定义是否需要一个完全限定的类名,直到全局范围
- 为什么c++允许成员函数定义中实例的私有成员访问
- Qt基类函数定义
- C++函数定义中参数列表后面额外一对括号的含义