test_2.cpp中定义继承类test2,并实现虚函数virtual void display()const的定义,并实现一个创建类函数和一个销毁类指针函数。
main.cpp中实现动态的调用不同库中的display()方法。
1: #include
近期染色体为中心的hpp计划(chromosome-centrichumanproteomeproject,c-hpp)及基于人体组织的hpp图谱(tissue-basedmapofhumanproteome)已取得一定进展。
test_base.hpp中定义一个含有纯虚函数virtualvoid display() const = 0的基类。
#include"test_base.hpp"。
#ifndef TEST_BASE_HPP
#define TEST_BASE_HPP
#include
using namespace std;
class test_base {
public:
test_base(){}
virtual~test_base() {}
voidcall_base() {
cout << "call base" << endl;
}
virtual voiddisplay() const = 0 ;
};
// the types of the class factories
typedef test_base* create_t();
typedef void destroy_t(test_base*);
#endif
g++ test1.cpp -otest1。
7.将test1.cpp中的内容替换为以下代码:。
add_executable (project_namemain.cpp test1.cpp test2.cpp)。
一个test1.cpp文件。
#include "test_base.hpp"
class test1 : public test_base {
public:
virtual voiddisplay() const {
cout << "Running in test1.so Now" << endl;
}
};
// the class factories
extern "C" test_base* create() {
return newtest1;
}
extern "C" void destroy(test_base* p) {
deletep;
}
////////////////////////////////test1.cpp//////////////////////////////////////////////////////
#include "test_base.hpp"
class test2 : public test_base {
public:
virtual voiddisplay() const {
cout << "Running in test2.so Now" << endl;
}
};
// the class factories
extern "C" test_base* create() {
return newtest2;
}
extern "C" void destroy(test_base* p) {
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-90978-8.html
真是的