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

靜態(tài)常量與#define

static const vs #define(靜態(tài)常量與#define)
本文介紹了靜態(tài)常量與#define的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

使用 static const 變量比使用 #define 預(yù)處理器更好嗎?或者這取決于上下文?

Is it better to use static const vars than #define preprocessor? Or maybe it depends on the context?

每種方法的優(yōu)點/缺點是什么?

What are advantages/disadvantages for each method?

推薦答案

就個人而言,我討厭預(yù)處理器,所以我總是使用 const.

Personally, I loathe the preprocessor, so I'd always go with const.

#define 的主要優(yōu)點是它不需要內(nèi)存來存儲您的程序,因為它實際上只是用文字值替換一些文本.它還有一個優(yōu)點是它沒有類型,所以它可以用于任何整數(shù)值而不會產(chǎn)生警告.

The main advantage to a #define is that it requires no memory to store in your program, as it is really just replacing some text with a literal value. It also has the advantage that it has no type, so it can be used for any integer value without generating warnings.

const"的優(yōu)點是可以限定范圍,可以在需要傳遞對象指針的情況下使用.

Advantages of "const"s are that they can be scoped, and they can be used in situations where a pointer to an object needs to be passed.

不過,我不知道您對static"部分的確切含義.如果您是全局聲明,我會將它放在匿名命名空間中,而不是使用 static.例如

I don't know exactly what you are getting at with the "static" part though. If you are declaring globally, I'd put it in an anonymous namespace instead of using static. For example

namespace {
   unsigned const seconds_per_minute = 60;
};

int main (int argc; char *argv[]) {
...
}

這篇關(guān)于靜態(tài)常量與#define的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉(zhuǎn)換為 HSV 并將 HSV 轉(zhuǎn)換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉(zhuǎn)換為字符串?)
When to use inline function and when not to use it?(什么時候使用內(nèi)聯(lián)函數(shù),什么時候不使用?)
Examples of good gotos in C or C++(C 或 C++ 中好的 goto 示例)
Significance of ios_base::sync_with_stdio(false); cin.tie(NULL);(ios_base::sync_with_stdio(false) 的意義;cin.tie(NULL);)
Is TCHAR still relevant?(TCHAR 仍然相關(guān)嗎?)
主站蜘蛛池模板: 久久久久久久综合 | 国产二区视频在线观看 | av在线精品 | 啪啪综合网 | 欧美理论在线观看 | 国产黄a三级三级三级看三级男男 | 国产精品福利视频 | www.国产一区 | 国产美女精品视频 | 亚洲成a人片 | 日本免费在线观看视频 | 国产精品五区 | 国产a久久麻豆入口 | 亚洲福利视频一区 | 97caoporn| 日韩三级一区 | 日韩一区二区在线播放 | av大全在线观看 | 九九视频在线 | 日韩综合在线观看 | 色综合五月 | www.草逼| 中文字幕99 | 三级av在线 | 亚洲国产福利 | 怡红院亚洲 | 日韩在线综合 | 一区久久 | 免费网站黄色 | 日韩亚洲欧美在线 | 一级片久久| 人人干人人草 | 日韩欧美一区在线 | 久久机热这里只有精品 | 日韩在线不卡视频 | 黄色一级免费看 | 美女黄色小说 | 人人爱人人草 | 秋霞国产 | 亚洲成人中文字幕 | 亚洲福利在线观看 |