小编Gya*_*uyn的帖子

将重载函数与其多态参数匹配

好吧,标题是满口的,我认为这可能是为什么很难通过谷歌或这个网站找到答案.可能只是因为我不知道如何正确表达问题,但这里有:

我在SimpleOpenGLRenderer类中有一系列方法,它们都采用扩展Model类的单个参数.因此,根据模型的类型,渲染器将调用知道如何渲染它的正确方法.以下是基于该问题的简化可执行示例:

#include <stdio.h>

class Model {};

class Cube : public Model {};

class Sphere : public Model {};

class Renderer
{
  public:
    virtual void renderModel(const Model& model) = 0;
};

class SimpleOpenGLRenderer
{
  public:
    void renderModel(const Cube& model)
    {
      printf("Render the cube.\n");
    }

    void renderModel(const Model& model)
    {
      printf("Throw an exception, my renderer does not support the model type you have provided.\n");
    }

    void renderModel(const Sphere& model)
    {
      printf("Render the sphere.\n");
    }
};

int
main(int …
Run Code Online (Sandbox Code Playgroud)

c++ polymorphism overloading function

18
推荐指数
1
解决办法
7123
查看次数

使用a4j:支持更新模型和视图,为下一个按钮/提交操作做好准备

问题

我们有一个基于swing的前端用于企业应用程序,现在正在为它实现一个(现在更简单)JSF/Seam/Richfaces前端.

某些页面包含的字段在编辑时应导致其他字段因此而更改.我们需要立即向用户显示此更改(即他们不必按下按钮或任何其他内容).

我已成功使用h:commandButton并通过添加onchange="submit()"导致其他字段更改的字段来实现此功能.这样,表单提交在他们编辑字段时发生,其他字段作为结果更新.

这在功能上运行良好,但特别是当服务器处于显着负载(经常发生)时,表单提交可能需要很长时间,并且我们的用户在此期间继续编辑字段,然后在对onchange="submit()"请求的响应时恢复渲染.

为了解决这个问题,我希望能够实现以下目标:

  1. 在编辑字段时,如果需要,处理该字段,并且重新呈现它修改的字段(以便用户在此期间进行的任何其他编辑不会丢失).
  2. 按下按钮后,所有字段都将正常处理和重新渲染.

(不稳定)解决方案

好吧,我认为首先展示一下我的页面可能是最容易的.请注意,这只是一个摘录,有些页面会有很多字段和许多按钮.

<a4j:form id="mainForm">
    ...
    <a4j:commandButton id="calculateButton" value="Calculate" action="#{illustrationManager.calculatePremium()}" reRender="mainForm" />
    ...
    <h:outputLabel for="firstName" value=" First Name" />
    <h:inputText id="firstName" value="#{life.firstName}" />
    ...
    <h:outputLabel for="age" value=" Age" />
    <h:inputText id="age" value="#{life.age}">
        <f:convertNumber type="number" integerOnly="true" />
        <a4j:support event="onchange" ajaxSingle="true" reRender="dob" />
    </h:inputText>
    <h:outputLabel for="dob" value=" DOB" />
    <h:inputText id="dob" value="#{life.dateOfBirth}" styleClass="date">
        <f:convertDateTime pattern="dd/MM/yyyy" timeZone="#{userPreference.timeZone}" />
        <a4j:support event="onchange" …
Run Code Online (Sandbox Code Playgroud)

jsf seam richfaces ajax4jsf

6
推荐指数
1
解决办法
9786
查看次数

几乎从纯虚拟(接口)类继承是一个很好的约定吗?

我经常使用纯虚拟类(接口)来减少当前项目中不同类的实现之间的依赖关系.我甚至拥有层次结构并不罕见,在这些层次结构中我有纯虚拟和非纯虚拟类来扩展其他纯虚拟类.以下是这种情况的一个例子:

class Engine
{ /* Declares pure virtual methods only */ }

class RunnableEngine : public virtual Engine
{ /* Defines some of the methods declared in Engine */ }

class RenderingEngine : public virtual Engine
{ /* Declares additional pure virtual methods only */ }

class SimpleOpenGLRenderingEngine : public RunnableEngine,
    public virtual RenderingEngine
{ /* Defines the methods declared in Engine and RenderingEngine (that are not
     already taken care of by RunnableEngine) */ }
Run Code Online (Sandbox Code Playgroud)

双方RunnableEngineRenderingEngine延长 …

c++ multiple-inheritance virtual-inheritance pure-virtual

5
推荐指数
1
解决办法
801
查看次数

dlopen是否重新加载已加载的依赖项?如果是这样,有什么影响?

我有一个代号为的程序foo.foo取决于common.so并以正常方式与它相关联(抱歉,我不知道技术方​​式).何时foo运行它然后bar.so使用动态加载dlopen().到现在为止还挺好.

但是,bar.so也取决于common.so.是否会dlopen()重新加载common.so(从我读过的内容中递归加载任何所需的依赖项),还是会检测到它已经加载了?如果它重新加载它,是否会导致我的程序出现问题?双方foobar.so需要看到的变化common.so,要么他们做出静态变量存在.

也许我的设计需要改变或需要使用-rdynamic(我还不太了解)?

c++ gcc dlopen

5
推荐指数
1
解决办法
959
查看次数