V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
linux40
V2EX  ›  C++

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

  •  1
     
  •   linux40 · 2020-12-10 20:34:36 +08:00 · 1157 次点击
    这是一个创建于 1227 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这种特征如下:

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

    代码实例如下:

    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 条回复    2020-12-12 02:11:23 +08:00
    linux40
        1
    linux40  
    OP
       2020-12-10 21:51:52 +08:00
    对了,还有一点要求,Derived0::foo 不能抛异常,比如没有 new 之类的。
    linux40
        2
    linux40  
    OP
       2020-12-11 19:35:06 +08:00
    kuso,人工顶一下。。。
    secondwtq
        3
    secondwtq  
       2020-12-12 00:05:27 +08:00   ❤️ 1
    我倒是觉得这个主题符合这种特征: https://en.wikipedia.org/wiki/XY_problem
    linux40
        4
    linux40  
    OP
       2020-12-12 02:11:23 +08:00 via Android
    @secondwtq 这可能是一种线索。有实际的开源项目例子就好了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2552 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 15:46 · PVG 23:46 · LAX 08:46 · JFK 11:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.