简体   繁体   中英

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.

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:

IDE 截图

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

When Comp is 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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM