- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
编辑澄清:
有没有办法将一个类的 header 拆分到多个文件中,以便其他类可以只包含它应该被允许使用的该类实现的部分?
----下面是我想要的实现的具体细节:---- 不是必读的!
无论如何,我正在创建一个实体组件系统。我想按如下方式构建它:
有一个“EntityPool”对象,主要作为实体及其组件的内存存储/管理器存在。我想从我的“游戏”类中获得指定程度的访问权限(例如,构造/破坏池的能力,以及访问组件数组的能力,以及迭代所有“可渲染”组件的能力)。
有一个“EntityFactory”基类,我希望它能更大程度地访问实体池。它会被“游戏”类使用,如下所示:
GruntEntityFactory ef(&EntityPool); //GruntEntityFactory inherits from EntityFactory
ef.produce();
然后,实体工厂将使用其对实体池的访问权限来创建必要的组件并将它们放置到位。
这里要注意的是,“游戏”只能创建 EntityPool 并读取其内容,但不能直接更改其内容。另一方面,继承 EntityFactory 的所有内容,我想授予管理 EntityPool 内容的权限。
有没有一种方法可以在每个文件中包含不同的 EntityPool header ,这样每个文件都只“知道”它可以访问的函数?这是执行此操作的最佳方法吗(假设可能)?
此外,我意识到这与 EntityPool 和 EntityFactories 紧密结合。那是故意的。而且,我不想列出我在 EntityPool 中作为友元类创建的每个 EntityFactory。
谢谢!
说明示例代码
//In my Game Class
#include "entitypool.h"
#include "entityfactory_grunt.h"
...
EntityPool ep(); //Construct an EntityPool
GruntEntityFactory gef(&ep); //Pass an EntityPool pointer to an EntityFactory
gef.produce(); //Call produce on GruntEntityFactory, and have it add appropriate components to the EntityPool
//I would like this next line to not be allowed. Game shouldn't be able to
//directly manipulate the components/ other internal EntityPool structure.
//However, I WOULD like EntityFactories to retain the ability to do so.
//(otherwise, how would EntityFactory.produce() work?)
ep.addComponent(PhysicsComponent pc(1, 2, 3));
//I WOULD like Game to be able to access certain functions of EntityPool
for(int i = 0; i < ep.numPhysicsComponents; i++)//Like the count of entities
physicsSolver.update(ep.physicsComponents[i]);//And the ability to update/render components
好的。所以希望这是一个足够明智的例子来了解我想要的东西。标题的原因是我对如何实现这一点的第一直觉是有 2 个头文件。
//EntityPool_GameAccess.h
//This file would contain prototypes for the functions utilized by Game, but NOT the ones
//that game is not allowed to see.
class EntityPool
{
public:
int numPhysicsComponents();
PhysicsComponent getPhysicsComponent(int i);
};
和
//EntityPool_FactoryAccess.h
//This file would contain prototypes for the functions that only ought be used
//by classes specifically built to manipulate entitypool
class EntityPool
{
public:
void addPhysicsComponent(PhysicsComponent pc);
int numPhysicsComponents();
PhysicsComponent getPhysicsComponent(int i);
};
显然,这些示例都经过了简化。希望我仍然理解这个想法:我想要一个具有特定类可以访问的某些函数以及其他类可以访问其他函数的类。
最佳答案
好的。我终于在 StackOverflow 上的另一个问题中找到了答案:Making classes public to other classes in C++
帕特里克回答的底部:
Unfortunately, there is no way in C++ to make only a part of your class public to a limited set of other classes.
关于c++ - 如何跨文件分配 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21369932/
我在让“@header”或任何其他@规则在ANTLR中工作时遇到麻烦。具有非常基本的语法,如下所示: grammar test; options { language = CSharp2;
我对来源和寄宿有疑问 我有一个ajax页面“Page A”,它将称为ajax提要“Page B” 我看到来自ajax调用的“页面B”的请求 header 具有源“http://mydomain.com
我在 pandas 中使用了数据透视表并获得了所需的数据框格式,但现在我有两行标题。数据透视表后的结果数据框如下: scenario Actual Plan
我在 pandas 中使用了数据透视表并获得了所需的数据框格式,但现在我有两行标题。数据透视表后的结果数据框如下: scenario Actual Plan
我想在主机将它们发送到网络之前修改数据包头(IP 头、TCP 头)。 例如,如果我使用 firefox 进行浏览,那么我想拦截所有来自 firefox 的数据包并修改 IP/TCP header ,然
我的 header 内容被包装到#header 中,但是当我设置边框显示结构时,它显示我的#header 的内容出现在#header 本身之后。可能是什么问题?这是我的代码: #header { bo
我是一名 Web 开发人员,使用过 PHP 和 .NET。有一年多的 Web 工作经验,我一直无法彻底了解浏览器缓存功能,希望这里的 Web Gurus 可以帮助我。我心中的问题是: 浏览器实际上是如
伙计们,我有一个问题,我不知道如何在一个 header 中连接多个 header ,我们称它为“主 header ”并使用该 header 中的函数,例如 // A.h #include class
我有一个包含 SOAP 消息的 XMLHTTPRequest。 我想添加用于标识消息并将由 C# Web 服务使用的 guid。 GUID 的目标是识别特定用户,并应护送所有用户请求以在服务器上进行身
我一直在阅读粘性标题,这是我目前所发现的。第一个粘性 header 效果很好,但是当它遇到第一个 header 时,我如何向上滚动第一个 header 并使第二个 header 卡住? http://
我想将当前基于 TableView 的数据网格转换为新的 UICollectionView 类。 这就是我当前的网格的样子: 我的网格有两个标题: 年份(2006a、2007a 等)和 类型(“收入”
我目前正在使用 Apollo 服务器。我正在尝试在响应 header 中设置一个属性。并且此属性是从客户端 graphQL 请求 header 中检索的。 我在网上查了一下。并看到了诸如使用插件或扩展
我的 Controller 的方法需要设置一个标题,例如X-Authorization .创建新对象( store Action )后,我执行转发以显示新创建的对象( show Action ): $
我正在研究一些关于 VLAN 的事情,发现了 VLAN 标签 和 header 。 如果我们有标准 802.3 以太网帧 的 MTU(1518 字节), header 802.3 中包含什么? 另外,
我是放心和 Java 的新手,我正在尝试做一个非常基本的测试来检查 API 的响应是否为 200 ok。 谁能告诉我我需要在下面的脚本中更改什么才能传递多个 header Id、Key 和 ConId
在我的项目中,我需要知道 zlib header 是什么样的。我听说它相当简单,但我找不到 zlib header 的任何描述。 例如,它是否包含魔数(Magic Number)? 最佳答案 zlib
我正在使用 JMeter 测试 HTTP 服务器,该服务器接受并验证 APIKey 并在成功时返回一个有时限的 token 。如果我有 token ,我想发送一个 token ;如果没有,我想发送一个
以太网 header 是什么样的? 是吗: 1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|
我们的应用程序支持 CORS 配置 header 。我在两个不同的主机上分别配置了 testApp。两种设置都相互独立工作。host1 上的应用程序配置有 CORS header Access-Con
tlhelp32.h 不包含 windows.h 本身是有原因的吗?我一直在与大量的编译器错误作斗争,因为我在包含 tlhelp32.h 之后包含了 windows.h。这是设计决定还是出于什么原因?
我是一名优秀的程序员,十分优秀!