在具有多个成员的类的成员初始化期间,似乎希望能够捕获由任何特定成员初始化程序生成的异常,以包装在额外的上下文中以便重新抛出,但是函数 try 块的语法没有出现为了适应这一点。
#include <stdexcept>
#include <string>
#include <sstream>
using namespace std::literals::string_literals;
[[noreturn]]
int thrower() { throw std::runtime_error("unconditional throw"s); }
int nonThrower() { return 3; }
class C {
int x;
int y;
public:
C();
};
class XError : public std::runtime_error {
public:
XError(const std::string& what) : std::runtime_error((std::stringstream() << "xerror: "s << what).str()) {};
};
class YError : public std::runtime_error {
public:
YError(const std::string& what) : std::runtime_error((std::stringstream() << "yerror: "s << what).str()) {};
};
C::C() try:
x(nonThrower()),
y(thrower()) {}
catch(const …Run Code Online (Sandbox Code Playgroud) 让我们假设我的问题是我希望用户能够通过一个控件选择一定数量的苹果和一定数量的梨。我在 iOS 捆绑的时钟应用程序的“计时器”部分看到了选择器,我喜欢它。
我完全想要那个,除了不是三列,我想要两列,而不是“小时”和“分钟”,我想要“苹果”和“梨”。
到目前为止,我能够将两个选择器并排放置,虽然它们不会像在同一个轮子上那样略微弯曲物品,但对于我现在的列问题来说已经足够了。不过,我还无法在行上放置标题。
这是我所拥有的:
render() {
let PickerIOSItem = PickerIOS.Item
return (
<View style={styles.container}>
<PickerIOS style={styles.column}>
<PickerIOSItem value={1} label="0" />
<PickerIOSItem value={2} label="1" />
<PickerIOSItem value={3} label="2" />
<PickerIOSItem value={4} label="3" />
<PickerIOSItem value={5} label="4" />
</PickerIOS>
<PickerIOS style={styles.column}>
<PickerIOSItem value={1} label="0" />
<PickerIOSItem value={2} label="1" />
<PickerIOSItem value={3} label="2" />
<PickerIOSItem value={4} label="3" />
<PickerIOSItem value={5} label="4" />
</PickerIOS>
</View>
);
}
Run Code Online (Sandbox Code Playgroud)
styles.container有display: flex和flex-direction: row,和styles.column了width: 49%。