|
代码在 Visual Studio 中可以编译,但在 STM32CubeIDE 中无法编译。 std::tuple<int, int, int> testTuples() { return { 1, 2, 3 }; }; struct Test { int a = 0, b = 0, c = 0; }; int main() { auto [a, b, c] = testTuples(); void* mem = malloc(3 * sizeof(int)); auto test = new(mem)Test; } 令人惊讶的是,"std::pair" 可以正常工作。 尽管tuples本质上只是一种语法,但没有placement new的支持确实很麻烦。因为这样,要么必须在需要时手动重新初始化结构体,要么就得分配新的内存,要么就得使用 “memset ()” 。
|