Re[6]: Можно забиндить конструктор?
От: Pavel Chikulaev Россия  
Дата: 08.02.06 13:05
Оценка:
Здравствуйте, ekamaloff, Вы писали:

E>Не в хипе и не в стеке. А в "Const Data" (см. http://rsdn.ru/Forum/Message.aspx?mid=1663584&only=1
Автор: igna
Дата: 07.02.06
).

Нет такого "Const data". Есть static storage и static storage duration и строки как раз находятся там.
E>Изменять данные в такой строке ты не можешь.
Можно. Только будет UB см. 2.13.4/2
E>И правильней будет написать так:
E>
E>const char* = "test for string";
E>

+1
Добавлю:
Из C в C++ пришло неявное преобразование const char * в char *. Однако для любих других типов так не сработает:

4.2/2

A string literal (2.13.4) that is not a wide string literal can be converted to an rvalue of type “pointer to
char”; a wide string literal can be converted to an rvalue of type “pointer to wchar_t”. In either case,
the result is a pointer to the first element of the array. This conversion is considered only when there is an
explicit appropriate pointer target type, and not when there is a general need to convert from an lvalue to an
rvalue. [Note: this conversion is deprecated. See Annex D. ] For the purpose of ranking in overload resolution
(13.3.3.1.1), this conversion is considered an array-to-pointer conversion followed by a qualification
conversion (4.4). [Example: "abc" is converted to “pointer to const char” as an array-to-pointer conversion,
and then to “pointer to char” as a qualification conversion. ]


Решил проверить, и Comeau и VC скопилировали это
wchar_t * p = L"test for string";

В чем дело?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.