gpt4 book ai didi

c++ - STL列表题C

转载 作者:太空狗 更新时间:2023-10-29 20:18:18 25 4
gpt4 key购买 nike

我在 c: 中有列表指针

list<int> * pointer = (list<int> *)malloc(sizeof(list<int>));

当我尝试时:

pointer->push_back(1);

我得到错误,因为 malloc 没有调用列表构造函数。我知道在 C++ 中使用:

list<int> * pointer = new list<int>();

但我需要这个在 c 中吗?

有人知道这个的解决方案吗?

最佳答案

不,因为它们是不同的语言。仅仅因为名称中的普通字母后只有文本字符串“++”并不意味着任何东西 - 这在功能上等同于尝试在 Python 中使用 Java 容器。

如果你想使用STL,你必须使用C++编译器。

关于c++ - STL列表题C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4545064/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com