[英]C++ Builder bccarm error when calling std::vector::push_back with TObject descendant
I have some simple C++ code which won't be compiled by the Clang based C++11 compiler bccaarm of C++ Builder 10.1 Berlin.我有一些简单的 C++ 代码,它们不会被 C++ Builder 10.1 Berlin 的基于 Clang 的 C++11 编译器 bccaarm 编译。
This is the code:这是代码:
TComponent* Comp = new TComponent(this);
std::vector<TComponent*> Comps;
Comps.push_back(Comp);
And this is the error:这是错误:
[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')
[bccaarm 错误] stl_iterator.h(963):右值引用类型“value_type”(又名“System: classes::TComponent * __strong”)不能绑定到“__borland_class * isTObj __strong”类型的左值(又名“System: :Classes::TComponent * __strong')
The compiler stops at line 963 in the file stl_iterator.h:编译器在 stl_iterator.h 文件的第 963 行停止:
The other C++ compilers bcc32 and bcc32c(also Clang based) have no problems with this code.其他 C++ 编译器 bcc32 和 bcc32c(也基于 Clang)对这段代码没有问题。
When Comp
is not from type TComponent
or another descendant from TObject
the code compiles without any problem.当
Comp
不是来自TComponent
类型或TObject
的另一个后代时,代码编译没有任何问题。
I have no idea what is wrong with this code and why there is a problem with R and L values...我不知道这段代码有什么问题以及为什么 R 和 L 值有问题......
Does anybody know what to do here?有人知道在这里做什么吗?
To get the above code compiled the vector type has to be defined as an unsafe pointer.要编译上述代码,必须将向量类型定义为不安全指针。
TComponent* Comp = new TComponent(this);
std::vector<__unsafe TComponent*> Comps;
Comps.push_back(Comp);
I openened a support case for an other problem I had.我为我遇到的另一个问题打开了一个支持案例。 The embarcadero support gave me the following information which I applied to this problem and it seems to work:
embarcadero 支持给了我以下信息,我将这些信息应用于这个问题,它似乎有效:
__unsafe
tells the compiler that object lifetimes will be handled and no ARC code is generated for the objects__unsafe
告诉编译器将处理对象生命周期,并且不会为对象生成 ARC 代码
More about this topic:有关此主题的更多信息:
http://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic_Reference_Counting_in_C%2B%2B#weak_and_unsafe_pointers http://docwiki.embarcadero.com/RADStudio/Berlin/en/Automatic_Reference_Counting_in_C%2B%2B#weak_and_unsafe_pointers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.