Archived Forum Post

Index of archived forum posts


C++ methods returning strings?

Aug 26 '14 at 11:21

Please note that these 2 pages write "quickGetStr" in different case style:

And a question:
Is it correct (in the sample) that I don't need to release the result of quickGetStr?


Each Chilkat C++ method that returns a string has 2 forms: (1) An uppercase form that returns the string in the final output-only "CkString &" argument, and (2) a lowercase alternative form that returns a "const char ". The lowercase alternative returns a pointer to internal memory that can be assured to be valid only after the call (prior to the Chilkat object being deleted, and prior to other lowercase string alternative methods being called). A "const char " should not (and cannot) be deleted by the application. When something is a "const <type> *", it is not deletable and the "const" SHOULD signify that code does not own the memory or it points to something that is not on the heap and therefore should not be deleted.

Both forms of the "QuickGetStr" method are as follows:

bool QuickGetStr(const char url, CkString &outStr);
const char *quickGetStr(const char url);

Likewise, each string property has two forms: (1) a "get_PropName(CkString &outStr)" form, and (2) a lowercase alternative form that is the property name returning a "const char *". For example:

void get_ProxyDomain(CkString &str);
const char *proxyDomain(void);