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

靜態常量與#define

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

問題描述

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

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

每種方法的優點/缺點是什么?

What are advantages/disadvantages for each method?

推薦答案

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

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

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

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"的優點是可以限定范圍,可以在需要傳遞對象指針的情況下使用.

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[]) {
...
}

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

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

相關文檔推薦

Algorithm to convert RGB to HSV and HSV to RGB in range 0-255 for both(將 RGB 轉換為 HSV 并將 HSV 轉換為 RGB 的算法,范圍為 0-255)
How to convert an enum type variable to a string?(如何將枚舉類型變量轉換為字符串?)
When to use inline function and when not to use it?(什么時候使用內聯函數,什么時候不使用?)
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 仍然相關嗎?)
主站蜘蛛池模板: 日本精品久久 | 91在线视频在线观看 | 91精品国产综合久久久久久丝袜 | 99在线免费观看 | 欧美久久一级特黄毛片 | 亚洲一区二区三区免费 | 国内自拍偷拍 | 91在线一区 | 国产精品一区二区视频 | 国产激情偷乱视频一区二区三区 | 国产精品1区 | 国产成人精品久久 | 热99精品视频 | 在线视频一区二区 | 国产一区中文字幕 | 久草在线 | www.色五月.com | 午夜久久久 | 99精品视频网 | 欧美成人精品 | 男女在线网站 | 中文字幕一区在线 | 亚洲视频免费观看 | 日日夜夜天天综合 | 欧美精品久久久 | 老外几下就让我高潮了 | 日p视频免费看 | 久久精品久久久 | 黄色国产在线视频 | 精品久久国产 | 美女天堂| 国产一区免费 | 日本高清视频在线播放 | 中文字幕一区二区视频 | 久久国产精品网 | 高清一区二区三区 | 成人av鲁丝片一区二区小说 | 亚洲国产高清在线观看 | 97偷拍视频| 天天看天天摸天天操 | 国产一区免费视频 |