小编wmj*_*gla的帖子

为什么抛出异常不被视为在运行时返回不同数据类型的技术?

我心里有这样的想法:

// This is called at multiple locations and each handles the returned object
// differently. Handling also differs depending on the returned object type.
void GetObject() {
    // Check runtime condition

    // Object1 and Object2 are completely dissimilar and do not share a base class.
    if (condition1) {
        // Operations to prepare for construction of Object1
        throw Object1{ var1, var2, var3 };
    }
    if (condition2) {
        // Operations to prepare for construction of Object2
        throw Object2{ var4, var5 }; …
Run Code Online (Sandbox Code Playgroud)

c++ exception return-type c++11

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

标签 统计

c++ ×1

c++11 ×1

exception ×1

return-type ×1