小编Que*_*ing的帖子

C++多态性和覆盖

我很难在C++中使用它,我已经用C#进行了管理,但是我没有使用C++,所以我不确定语法.

这个目的是为了一个简单的状态管理器,每个状态都从一个名为"state"的基类继承.

我已经压倒性地工作,但我似乎无法管理多态性方面.那就是我不能有一个对象"State currentState"并将该对象设置为等于"menuState"并让它运行所需的函数,我知道这是因为它只找到State类的签名但我不确定如何躲开它.这是一些简化的代码,以便有人可以帮助我理解.

// stringstreams
#include <iostream>
#include <string>
#include <sstream>
using namespace std;

// State.h
class State{
public:
  virtual void drawState();
};

// State.cpp
void State::drawState() {
    cout << "Base state.\n";
}

// MenuState.h
class MenuState: public State {
public:
  virtual void drawState();
};


// MenuState.cpp
void MenuState::drawState() {
    cout << "Menu state.\n";
    State::drawState();
}

int main ()
{
    State currentState;
    MenuState menuState;

    currentState = menuState;
    currentState.drawState();

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果您更改"State currentState"以创建MenuState的对象,则代码将按照我的要求运行,但是我需要它作为父类,以便我可以将当​​前状态设置为将来创建的其他状态,例如作为GameState.

谢谢.

c++ polymorphism inheritance overriding

2
推荐指数
1
解决办法
1422
查看次数

类的自定义格式

我当前正在使用 Serilog,我希望能够将一个类传递给记录器并让它在输出到文本文件之前以自定义格式记录。有点类似于IFormatProvider。我也发现了ITextFormatter,但我不确定这是否是正确的实施方式。我想要一个定制水槽吗?

serilog

2
推荐指数
1
解决办法
1121
查看次数

时间/框架问题与茉莉花大理石使用冷热

我有一个人们可以在这里下载的快速演示:https://stackblitz.com/edit/angular-vczzqp只需点击右上角的导出,在您最喜欢的终端中运行installng test使用您喜欢的浏览器.

对我来说,基本上问题似乎是Jasmine的内部时间与对象不匹配.

下面是测试以及我得到的确切错误.请参阅app/Test下的示例以获取完整的测试类

it('should return a GET_GENERIC_FAILED when the services throws', () => {
    const action = new genericActions.GetAllGenericAction();

    genericsService.getAllGenerics.and.returnValue(Observable.throw({}));

    actions$.stream = hot('a', { a: action });
    const expected = cold('b', { b: new genericActions.GetGenericFailedAction() });

    expect(effects.getAllGenerics).toBeObservable(expected);
});
Run Code Online (Sandbox Code Playgroud)

而错误

Expected
    [Object({
        frame: 0,
        notification: Notification({
            kind: 'N',
            value: GetGenericFailedAction({
                type: '[GENERIC] Get Generic Failed'
            }),
            error: undefined,
            hasValue: true
        })
    }), Object({
        frame: 0,
        notification: Notification({
            kind: 'C',
            value: undefined,
            error: …
Run Code Online (Sandbox Code Playgroud)

jasmine angular jasmine-marbles

2
推荐指数
1
解决办法
2512
查看次数

使用 FromQuery 时是否可以将类对象默认为 null

public class Filter
{
    public string Property1 { get;set; }
    public string Property2 { get;set; }
}
Run Code Online (Sandbox Code Playgroud)
[HttpGet("/search")]
public IActionResult Search([FromQuery] Filter filter)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我想知道如果filter我要调用/search.

现在filter不会为空,但它的每个属性都是。这可能是因为模型绑定正在创建类的默认实例,以使用它在查询字符串中找到的属性填充它。

我正在使用dotnet core 2.2.

c# .net-core asp.net-core

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

场景失败时结束加特林模拟但生成报告

我有代码,如果它失败,当前不会运行我的场景;

//Defined outside of the scenario scope
var simulationHealthy = true

//defined within the scenario
.exec((session: io.gatling.core.session.Session) => {
  if (session.status == KO) {
      simulationHealthy = false
  }
    session
  })
Run Code Online (Sandbox Code Playgroud)

然而,我的模拟一直运行,直到模拟设置的持续时间结束,尽管场景不会继续执行。

我想要做的是让场景在我定义的条件下失败(类似于断言),并且整个模拟也在那一点失败,并生成报告。

谢谢

编辑:我在 IntelliJ IDE 中运行这些测试。需要以编程方式结束模拟。

gatling

0
推荐指数
2
解决办法
7211
查看次数