C++

Miscellaneous Forums/General Discussion/C++

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

C doesnt fully support OOP though.

Yeah, C is a non-OOP language, so it has no OOP support except I guess you could say structs. But C struct's really isn't object oriented programming, it's just object oriented data.

Yahfree: C++ should be able to return a string just fine. What is the error?

No expert, but dont you need to return array itself, rather than the class?

return RetString.c_str();

No, the string class is totally self contained - if you use C++ strings, then there's absolutely no need to even be aware of the C style, unless of course you need to interface with code that uses C-style strings (which is the purpose of c_str).

Actually, returning RetString.c_str() is very dangerous and would lead to unexpected behavior - if your RetString object was defined locally to the function it's returning from, then after the function returns, RetString will be deleted, and so will it's c_str() value. And due to the way memory is managed, you may still get the proper string value back unless some other variable overwrites it later on, or in another thread.