gpt4 book ai didi

android - 使用 TObject 后代调用 std::vector::push_back 时出现 C++ Builder bccarm 错误

转载 作者:行者123 更新时间:2023-11-30 05:27:42 24 4
gpt4 key购买 nike

我有一些简单的 C++ 代码,它们不会被 C++ Builder 10.1 Berlin 的基于 Clang 的 C++11 编译器 bccaarm 编译。

这是代码:

TComponent* Comp = new TComponent(this);
std::vector<TComponent*> Comps;
Comps.push_back(Comp);

这是错误:

[bccaarm error] stl_iterator.h(963): rvalue reference to type 'value_type' (aka 'System: classes::TComponent * __strong') can not be bound to lvalue of type '__borland_class * isTObj __strong' (aka 'System::Classes::TComponent * __strong')

编译器在文件 STL_iterator.h 的第 963 行停止:

Screenshot of IDE

其他 C++ 编译器 bcc32 和 bcc32c(也是基于 Clang 的)对这段代码没有问题。

Comp 不是来自类型 TComponent 或来自 TObject 的另一个后代时,代码编译没有任何问题。

我不知道这段代码有什么问题以及为什么 R 和 L 值有问题......

有人知道怎么办吗?

最佳答案

要编译上述代码,必须将 vector 类型定义为不安全指针。

TComponent* Comp = new TComponent(this);
std::vector<__unsafe TComponent*> Comps;
Comps.push_back(Comp);

我为遇到的其他问题打开了一个支持案例。 embarcadero 支持为我提供了以下信息,我将其应用于此问题并且似乎有效:

__unsafe tells the compiler that object lifetimes will be handled and no ARC code is generated for the objects

有关此主题的更多信息:

http://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic_Reference_Counting_in_C%2B%2B#weak_and_unsafe_pointers

关于android - 使用 TObject 后代调用 std::vector::push_back 时出现 C++ Builder bccarm 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37134861/

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