- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我遇到过一个c++ demo编程源码,里面有一个名为A.h的头文件,还有一个名为X.so的共享库,A.h如下:
#if !defined(A_H)
#define A_H
class aAPI
{
public:
static aAPI* createaAPI(const char*FlowPath = "");
virtual void Init() = 0 ;
virtual void Release() = 0 ;
virtual const char *GetDay() = 0;
virtual void RegisterU(char *pU) = 0;
protected:
~aAPI(){};
};
#endif
API类中的所有函数都是纯虚函数,所以不能用来创建对象,这个 aAPI 的演示看起来像:
aAPI* ptr ;
ptr = aAPI::createaAPI("logtest");
strcpy(tradingDay, ptr->GetDay());
我正在尝试像这样编写 a.cpp 代码:
#include "a.h"
aAPI* aAPI::createaAPI(const char*FlowPath )
{
//return this ;
}
但我发现我无法返回 this,因为“this”对于静态成员函数不可用,然后我注意到 A.h 中的类 aAPI 没有私有(private)成员数据,所以我认为在 X.so 中,应该有代码来声明类 aAPI 私有(private)成员数据以保持由 createaAPI 或 RegisterU 传递的数据!!
我想知道在我的例子中 a.cpp 如何返回指向 aAPI 的指针,然后如何在 a.cpp 中声明 aAPI 的私有(private)成员数据?!
Edit :
Here comes the simple source for this case :
啊啊
#if !defined(A_H)
#define A_H
class aAPI
{
public:
static aAPI* createaAPI(const char*FlowPath = "");
virtual void Init() = 0 ;
virtual void Release() = 0 ;
virtual const char *GetDay() = 0;
protected:
~aAPI(){};
};
#endif
a.cpp
#include "a.h"
#include "b.h"
aAPI* aAPI::createaAPI(const char*FlowPath)
{
static aAPI* ptr = 0x00 ;
if(ptr==0x00)
{
ptr = new bAPI(FlowPath) ;
}
return ptr;
}
b.h
#if !defined(B_H)
#define B_H
#include "a.h"
class bAPI:public aAPI
{
private:
char path[100] ;
char strday[11] ;
public:
bAPI(const char*FlowPath)
{
strcpy(path,FlowPath) ;
}
virtual void Init() ;
virtual void Release() ;
virtual const char *GetDay() ;
} ;
void bAPI::Init()
{
strcpy(strday,"2014/01/02") ;
}
void bAPI::Release()
{
}
const char* bAPI::GetDay()
{
return strday;
}
#endif
amain.cpp
#include "a.h"
using namespace std ;
int main()
{
aAPI* ptr = aAPI::createaAPI("hello world") ;
ptr->Init();
cout << ptr->GetDay() << endl ;
}
然后:
g++ --std=c++0x a.cpp amain.cpp -o amain.exe
将完成演示! ....非常感谢!!!!
最佳答案
header 指定共享库符合的接口(interface)。该库很可能包含派生自 aAPI
的类以及 aAPI
方法的实现。 static aAPI* createaAPI(const char*FlowPath = "")
是一个工厂方法 - 它实例化派生类并将它们作为指向基类的指针返回。
您可以通过从 aAPI
派生它们并实现抽象方法来创建符合接口(interface)的自己的类。但是,只要链接到 X.so
,就无法使用工厂方法创建派生类,因为不允许提供它的第二个实现。
关于C++ demo编程,混淆类实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24860334/
就在我放松下来以为我对数组上下文中的指针有一个公平的理解时,我对下面的程序再次感到沮丧。我已经理解了数组 arr,arr 和 &arr 大小相同,但类型不同,但我无法牢牢掌握以下程序的输出。我尝试将其
这个问题在这里已经有了答案: Why whole structure can not be compared in C, yet it can be copied? (6 个答案) 关闭 9 年前。
今天我试图在我的代码中使用系统属性。当我输入 ./gradlew -Dorg.gradle.project.env=demo test 时,虽然我在脚本中成功打印了 env ,但发生了 NullPoi
概要 本节要实现的是多表关联查询的简单demo。场景是根据id查询某商品分类信息,并展示该分类下的商品列表。 1、Mysql测试数据 新建表Category(商品分类)和Product(商品
SpringCloud + Docker 的便利和强大真的超乎想象,我已经入坑了…好了,不说废话,记录一个简单的 Demo 供其他同学排坑。 前言 惯例不能丢,先上源代码:docker-demo
在没介绍正文之前先给大家介绍下数据更新方法支持的连贯操作方法有: 在上一篇文章中我们实现了数据的删除和批量删除,这一篇文章我们将实现数据的更新。 首先依然是预期效果图: 点击修
过滤html标签在php中可以有内置的函数了,但它过滤的太干净了,我们就整理了一下些利用正则来过滤指定html标签的例子,具体如下所示。 采集的时候有时候需要过滤掉多余的标签属性,比如 img标签
UIPickerView平常用的地方好像也不是很多,顶多就是一些需要选择的地方,这次项目需要这一个功能,我就单独写了一个简单的demo,效果图如下: 新增主页面弹出view,在主页面添
项目里面有一个需求,要对sql进行简单的语法分析 为了避免sql里面的字符串和注释对语法分析做干扰,我写了一个java函数,对sql进行修剪,删除里面字符串和注释,用空格代替 周末闲着没事,我用g
今天公司里的实习生跑过来问我一般App上广告的无限滚动是怎么实现的,刚好很久没写博客了,就决定写下了,尽量帮助那些处于刚学iOS的程序猿. 做一个小demo,大概实现效果如下图所示: 基本实
最近项目组同事跟我说遇到一个SQL性能问题,他说全表只有69条记录,客户端执行耗费了两分多钟,很不科学。我帮了分析出了原因并得到解决。下面小编安装类似表结构,构造了一个案例,测试截图如下所示:
新的一年又要到来了,各个大的公司又在这年末为大家送上了新春的祝福,支付宝还是延续了这几年的传统,在年末为大家送上了集五福的活动,为了大家能更快更好的扫出来大大的“福”,今天就带领大家利用python
我已经安装了http://download.jboss.org/jbpm/release/6.4.0.Final/jbpm-6.4.0.Final-installer-full.zip在这里找到htt
1、准备环境 服务器:linux(debian)+nginx+mysql+php 环境 框架:laravel 5.5 (确认能跑通) 需求:每天晚上1点执行定时操作 2、定时任务的步骤
下面通过一个小例子来说明cmake编译一个c++项目,生成可执行文件: 整理目录结构: CMake Lists.txt addlib build main.cpp 电脑上没有tree命
本文实例讲述了php实现基于微信公众平台开发SDK(demo)扩展的方法。分享给大家供大家参考。具体分析如下: 该扩展基于官方的微信公众平台SDK,这里只做了简单地封装,实现了一些基本的功能(如天
验证码不用多说,在 WEB-APP 中一般应用于:登录、注册、买某票、秒杀等场景。大家都接触过~可以说是千奇百怪,各式各样。 DEMO 目标功能 验证码页面输入。 页面更换验证码(异
下拉刷新在越来越多的app中使用,已经形成一种默认的用户习惯,遇到列表显示的内容时,用户已经开始习惯性的拉拉。在交互习惯上已经形成定性。之前在我的文章《ios学习笔记34—egotableviewp
一切尽在代码中,代码附有注释,欢迎大家参考。 ?
我试图找到答案,但没有任何结果。bin/console的一些命令和 ./psh.phar没有描述,所以很难理解它们的用途。 Shopware 6 中是否有从数据库中删除所有演示数据的命令? 最佳答案
我是一名优秀的程序员,十分优秀!