C++ Builder bccarm error when calling std::vector::push_back with TObject descendant

喜欢而已 提交于 2019-12-19 11:15:11

问题


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.

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')

The compiler stops at line 963 in the file stl_iterator.h:

The other C++ compilers bcc32 and bcc32c(also Clang based) have no problems with this code.

When Compis not from type TComponent or another descendant from TObject the code compiles without any problem.

I have no idea what is wrong with this code and why there is a problem with R and L values...

Does anybody know what to do here?


回答1:


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:

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

More about this topic:

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



来源:https://stackoverflow.com/questions/37134861/c-builder-bccarm-error-when-calling-stdvectorpush-back-with-tobject-descen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!