在 C++ 中使用结构体构造函数创建结构体实例

发布于 2025-01-17 07:35:14 字数 539 浏览 1 评论 0原文

我正在尝试围绕这次演讲进行思考:https://www.youtube.com/watch ?v=FXfrojjIo80 我在以下部分收到错误。这是简化版本。

template<typename... Ts>
struct parms : Ts... {};

template<typename... Ts>
parms(Ts... ) -> parms<Ts...>;

struct first{};
struct second{};

int main(int argc, char *argv[])
{   
    parms p(first{}, second{});  
}

我在 clang 上遇到编译错误,但在 gcc 上编译。 clang 不支持哪个 C++ 功能?显然,如果我将 ( 更改为 { ,它可以正常编译。

I am trying to wrap my mind around this talk: https://www.youtube.com/watch?v=FXfrojjIo80
I get an error on the following part. It is the simplified version.

template<typename... Ts>
struct parms : Ts... {};

template<typename... Ts>
parms(Ts... ) -> parms<Ts...>;

struct first{};
struct second{};

int main(int argc, char *argv[])
{   
    parms p(first{}, second{});  
}

I get a compile error on clang but compiles on gcc. Which C++ feature is this that is not supported in clang? Obviously if i change the ( to { it compiles fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春夜浅 2025-01-24 07:35:14

cppReference aptly称其为“聚集体的括号初始化”。

Cppreference aptly calls it "Parenthesized initialization of aggregates".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文