Cpstring; Constructors And Assignment - Casio ClassPad 300 Programming Manual

Sdk programming guide
Hide thumbs Also See for ClassPad 300:
Table of Contents

Advertisement

CPString

The CPString is a C++ class that encapsulates the memory allocation necessary for string
handling and multi-byte string handling, while still providing access to a raw character
buffer.
The character buffer is dynamically allocated, and may be reallocated when the string is
modified. If the string is modified, destroyed, or goes out of scope, any saved reference
to the string (a saved value from Text() or an iterator) should be considered invalid. The
exception is if an iterator is passed by reference to the operator that modified the string,
the iterator will be automatically updated.
CPString is not a reference counted string. If you pass a CPString as an argument to a
function it will make a complete copy of that string. This is not very efficient and can
waste a lot of memory. If you plan on passing a CPString as an argument to a function
you should pass it as a constant reference. For example:
void MyFunction(const CPString& str)
{
... do something ...
}

Constructors and Assignment

To create a new CPString you can use one of the following constructors:
CPString();
CPString(CPMCHAR c);
CPString(const PEGCHAR* s);
CPString(const CPString& y);
CPString(OBCD d, int num_digits);
Instead of explicitly creating a string with a constructor, the assignment and
concatenation characters are also defined as:
CPString& operator=(const CPString& y);
CPString& operator+=(const CPString& y);
CPString& operator+=(const PEGCHAR *y);
Here are some examples of creating CPStrings:
CPString str1;
str1 = "Hello world.";
str1 += " How are you?";
//str1 now equals "Hello world. How are you?"
CPString str2("I am fine.");
CPString str3(str2);
//str2=str3="I am fine."
99

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents