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