久久久久久久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 仍然相關嗎?)
主站蜘蛛池模板: 日韩爱爱网| 日本成人综合 | 久久大香 | 亚洲视频免费在线播放 | 992人人草| 亚洲一区二区久久 | 久久久久国产 | 亚洲国产精品一区二区www | 日韩在线 | 国产精品久久久久久久久久东京 | 日韩精品无码一区二区三区 | 日韩视频―中文字幕 | 五月花丁香婷婷 | 国产高清区| 成人精品视频免费 | 精品一区视频 | 91福利影院 | 国产亚洲精品精品国产亚洲综合 | 国产精品明星裸体写真集 | 欧美成人激情视频 | 9191成人精品久久 | 日本一二区视频 | 久久精品国产免费 | 一区中文字幕 | 国产一级精品毛片 | a毛片 | 男女啪啪高潮无遮挡免费动态 | 日本不卡一区二区 | 中国av在线免费观看 | 一区二区三区av夏目彩春 | 日本一二三区在线观看 | 午夜精品一区二区三区在线观看 | 国产精品久久久久无码av | 在线中文视频 | 亚洲国产一区二区三区在线观看 | 精品99爱视频在线观看 | 日韩精品| 成人夜晚看av | 亚洲精品视频一区二区三区 | 欧美福利 | 成人福利 |