# C++ Assignment Operator as the Object Pascal Implicit Operator

Jump to: navigation, search

This section describes the Appmethod C++ syntax for using the C++ assignment operator as the Object Pascal implicit operator.

In Object Pascal, the implicit operator is used for both assignment and construction. In C++ for Appmethod C++, it is possible to use the `operator=` only for assignment to the result type; but not for constructing the result type.

This syntax allows using the `operator=` for assignment in C++, the same as the implicit operator is used in the Object Pascal side.

A clear case that illustrates this is for example when using TValue in C++, where you have several implicit operators in Object Pascal that allow users to assign several types transparently.

Object Pascal:

```procedure doSomething();
var
a : TValue;
begin
a := 'assigning a string';
a := 123;
a := 3.14;
end;
```

Without the assignment operator, the C++ equivalent of the above Object Pascal code is the following.

C++:

```void doSomethingCppOld()
{
TValue a;
a = TValue::_op_Implicit(UnicodeString(L"assigning a string"));
a = TValue::_op_Implicit(123);
a = TValue::_op_Implicit(3.14L);
}
```

With the assignment operator, it is possible to write the C++ equivalent like this.

C++:

```void doSomethingCpp()
{
TValue a;
a = UnicodeString(L"assigning a string");
a = 123;
a = 3.14L;
}
```
Note: Whether you use the first or the second C++ version, it is important that you call the `UnicodeString` constructor when assigning a literal string, since its type is `const wchar_t *` (or `const char *`, if no `L` prefix is written). Otherwise, the pointer would be evaluated as a Boolean expression, because it is the best match, probably resulting in a call to an unexpected implicit operator.
{"ft_lang_label":"__label__en","ft_lang_prob":0.76364803,"math_prob":0.9624087,"size":1778,"snap":"2019-35-2019-39","text_gpt3_token_len":406,"char_repetition_ratio":0.16516347,"word_repetition_ratio":0.014134276,"special_character_ratio":0.24184477,"punctuation_ratio":0.15820895,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9715854,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-19T19:11:16Z\",\"WARC-Record-ID\":\"<urn:uuid:4abfd878-50c1-441d-abb6-be48b30d6d11>\",\"Content-Length\":\"24854\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:67bf8679-933b-4408-b492-fc84c995bf92>\",\"WARC-Concurrent-To\":\"<urn:uuid:084aba9d-044f-41c1-9780-5b70ebb0548a>\",\"WARC-IP-Address\":\"204.216.225.62\",\"WARC-Target-URI\":\"http://docwiki.appmethod.com/appmethod/1.17/topics/en/C%2B%2B_Assignment_Operator_as_the_Object_Pascal_Implicit_Operator\",\"WARC-Payload-Digest\":\"sha1:ZU5CJKZAHCPAGSSW6TU3HI2FSA57AWOR\",\"WARC-Block-Digest\":\"sha1:6PZO7DGFAH53GBEQTCSLAELU3ZI24DDW\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027314904.26_warc_CC-MAIN-20190819180710-20190819202710-00430.warc.gz\"}"}