linux40
V2EX  ›  C++

寻求带有某种特征的 C++项目

  •  1
     
  •   linux40 · Dec 10, 2020 · 1919 views
    This topic created in 2022 days ago, the information mentioned may be changed or developed.

    这种特征如下:

    • 项目中有一个基类和一些派生类;
    • 基类某个方法的默认实现,或者某些派生类的实现是抛出一个异常;(它们可能无法提供这个方法的实现,或者有别的什么原因。)
    • 有某个函数,接收这个基类为参数,并调用该方法;
    • 有某个函数,调用上面一条所描述的函数,调用时传递的对象有该方法的具体实现,而不是抛出异常。

    代码实例如下:

    struct Base {
        virtual void foo();
    };
    
    struct Derived0 : Base {
        virtual void foo() { /* do something */ }
    };
    
    struct Derived1 : Base {
        virtual void foo() { throw std::exception{ "Not Implemented!" }; }
    };
    
    void bar(Base &base)
    {
        /* do something */
        base.foo();
    }
    
    void baz()
    {
        Derived0 d0;
        bar(d0);
        /* do something */
    }
    
    4 replies    2020-12-12 02:11:23 +08:00
    linux40
        1
    linux40  
    OP
       Dec 10, 2020
    对了,还有一点要求,Derived0::foo 不能抛异常,比如没有 new 之类的。
    linux40
        2
    linux40  
    OP
       Dec 11, 2020
    kuso,人工顶一下。。。
    secondwtq
        3
    secondwtq  
       Dec 12, 2020   ❤️ 1
    我倒是觉得这个主题符合这种特征: https://en.wikipedia.org/wiki/XY_problem
    linux40
        4
    linux40  
    OP
       Dec 12, 2020 via Android
    @secondwtq 这可能是一种线索。有实际的开源项目例子就好了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5229 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 09:08 · PVG 17:08 · LAX 02:08 · JFK 05:08
    ♥ Do have faith in what you're doing.