久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

C++ 已棄用從字符串常量到“char*"的轉(zhuǎn)換

C++ deprecated conversion from string constant to #39;char*#39;(C++ 已棄用從字符串常量到“char*的轉(zhuǎn)換)
本文介紹了C++ 已棄用從字符串常量到“char*"的轉(zhuǎn)換的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)帶有 private char str[256];

為此我有一個(gè)顯式構(gòu)造函數(shù):

and for it I have an explicit constructor:

explicit myClass(const char *func)
{
    strcpy(str,func);
}

我稱之為:

myClass obj("example");

當(dāng)我編譯它時(shí),我收到以下警告:

When I compile this I get the following warning:

不推薦將字符串常量轉(zhuǎn)換為 'char*'

deprecated conversion from string constant to 'char*'

為什么會(huì)這樣?

推薦答案

當(dāng)您遇到以下情況時(shí),您會(huì)看到一條錯(cuò)誤消息:

This is an error message you see whenever you have a situation like the following:

char* pointer_to_nonconst = "string literal";

為什么?好吧,C 和 C++ 在字符串文字的類型上有所不同.在 C 中,類型是字符數(shù)組,而在 C++ 中,它是 constant 字符數(shù)組.在任何情況下,都不允許更改字符串字面量的字符,因此 C++ 中的 const 并不是真正的限制,而是更多的類型安全.出于安全原因,如果沒有顯式轉(zhuǎn)換,從 const char*char* 的轉(zhuǎn)換通常是不可能的.但是為了與 C 向后兼容,C++ 語言仍然允許將字符串文字分配給 char* 并警告您此轉(zhuǎn)換已被棄用.

Why? Well, C and C++ differ in the type of the string literal. In C the type is array of char and in C++ it is constant array of char. In any case, you are not allowed to change the characters of the string literal, so the const in C++ is not really a restriction but more of a type safety thing. A conversion from const char* to char* is generally not possible without an explicit cast for safety reasons. But for backwards compatibility with C the language C++ still allows assigning a string literal to a char* and gives you a warning about this conversion being deprecated.

因此,為了 const 的正確性,您在程序中的某處缺少一個(gè)或多個(gè) const .但是您向我們展示的代碼不是問題,因?yàn)樗鼪]有進(jìn)行這種已棄用的轉(zhuǎn)換.警告一定來自其他地方.

So, somewhere you are missing one or more consts in your program for const correctness. But the code you showed to us is not the problem as it does not do this kind of deprecated conversion. The warning must have come from some other place.

這篇關(guān)于C++ 已棄用從字符串常量到“char*"的轉(zhuǎn)換的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

boost_1_60_0 .zip installation in windows(Windows 中的 boost_1_60_0 .zip 安裝)
How do I get console output in C++ with a Windows program?(如何使用 Windows 程序在 C++ 中獲得控制臺(tái)輸出?)
How do I calculate the week number given a date?(如何計(jì)算給定日期的周數(shù)?)
OpenCV with Network Cameras(帶有網(wǎng)絡(luò)攝像機(jī)的 OpenCV)
Export all symbols when creating a DLL(創(chuàng)建 DLL 時(shí)導(dǎo)出所有符號(hào))
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門)
主站蜘蛛池模板: 久久久中文| 九九热热九九 | 亚洲第一视频 | 免费av毛片 | 成人国产午夜在线观看 | 亚洲 成人 av | 国产精品一区二区av | 欧美色综合天天久久综合精品 | 日韩精品一区二区三区中文字幕 | 福利影院在线看 | 国产一级片 | 另类视频在线 | 久久99精品久久久97夜夜嗨 | 欧美专区日韩专区 | 特一级黄色毛片 | 久久久久国产一区二区三区 | 国产在线观看一区二区 | 欧美a级成人淫片免费看 | 国产亚洲精品久久午夜玫瑰园 | 久久久精 | 久久精品视频12 | 日韩精品一区在线 | 亚洲一区在线日韩在线深爱 | 99精品九九 | 福利社午夜影院 | 亚洲精品视频在线观看免费 | 亚洲视频在线观看 | 色在线免费视频 | 欧美一级在线视频 | 日韩精品一区二区三区在线播放 | 精品国产91乱码一区二区三区 | 欧美中文在线 | 欧美一区永久视频免费观看 | 久久ww| 国产在视频一区二区三区吞精 | 久久久久久九九九九九九 | 欧美国产日韩成人 | 久久久久久久一区 | 欧美性久久久 | 狠狠躁18三区二区一区 | 国产午夜在线 |