Re: [問題] c++ class 內部 array size 宣告

作者: HiSUrMy (HiSUrMy)   2018-12-09 18:16:56
#ifndef A_H
#define A_H
class A
{
private:
static const int SIZE = 4;
int a[SIZE];
...
public:
...
};
#endif
or
#ifndef A_H
#define A_H
class A
{
private:
enum {SIZE = 40};
int a[SIZE];
...
public:
...
};
#endif
※ 引述《QQrzQQ (QQ)》之銘言:
: #ifndef A_H
: #define A_H
: #define SIZE 4
: class A{
: int a[SIZE];
: };
: #endif
: 如前面所寫的
: 因為我在使用上呼叫不同標頭檔
: 會遇到SIZE重複定義的問題
: 試著使用const int在class內
: 卻無法compile過
: 想請問大家如果遇到這種問題
: 又不想用new的方式
: 有沒有其他建議的寫法
: 謝謝 :)

Links booklink

Contact Us: admin [ a t ] ucptt.com