看板 Programming 關於我們 聯絡資訊
#ifndef A_H #define A_H #define SIZE 4 class A{ int a[SIZE]; }; #endif 如前面所寫的 因為我在使用上呼叫不同標頭檔 會遇到SIZE重複定義的問題 試著使用const int在class內 卻無法compile過 想請問大家如果遇到這種問題 又不想用new的方式 有沒有其他建議的寫法 謝謝 :) -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.114.75.203 ※ 文章網址: https://www.ptt.cc/bbs/Programming/M.1539938776.A.07D.html
LPH66: 支援 C++11 的可以用 constexpr 宣告 123.195.192.32 10/21 11:42
QQrzQQ: 不太懂,是指宣告const int的時候加關鍵字 140.114.75.171 10/22 11:22
QQrzQQ: 嗎 140.114.75.171 10/22 11:22
hare1039: 都在用 C++ 就別再用 #define 了 98.228.60.217 11/26 15:42
hare1039: constexpr int SIZE = 4; 就解決了 98.228.60.217 11/26 15:47