作者QQrzQQ (QQ)
看板Programming
标题[问题] c++ class 内部 array size 宣告
时间Fri Oct 19 16:46:13 2018
#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://webptt.com/cn.aspx?n=bbs/Programming/M.1539938776.A.07D.html
1F:推 LPH66: 支援 C++11 的可以用 constexpr 宣告 123.195.192.32 10/21 11:42
2F:→ QQrzQQ: 不太懂,是指宣告const int的时候加关键字 140.114.75.171 10/22 11:22
3F:→ QQrzQQ: 吗 140.114.75.171 10/22 11:22
4F:→ hare1039: 都在用 C++ 就别再用 #define 了 98.228.60.217 11/26 15:42
5F:→ hare1039: constexpr int SIZE = 4; 就解决了 98.228.60.217 11/26 15:47