数组初始化中的未知错误:非整型“const unsigned char[256]”静态数据成员的类内初始化无效

发布于 2024-08-19 07:35:45 字数 1786 浏览 2 评论 0原文

我试图制作一个 Intel 8080 CPU 模拟器(然后我想模拟使用它的《太空入侵者》)。

我编写了该 CPU 几乎完整的实现(感谢 MAME 和 Tickle 项目(主要是);)),除了未记录的指令(0x08、0x10、0x18、0x20、0x28、0x30、0x38、0x0CB、0x0D9、0x0DD、0x0ED、0x0FD)。

我只是在编译时遇到问题,我不知道为什么。

这是代码:

static const unsigned char cycles_table[256] =
{
    /*                       8080's Cycles Table                         */
    /*     0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F */
    /*0*/  4, 10,  7,  5,  5,  5,  7,  4,  0, 10,  7,  5,  5,  5,  7,  4,
    /*1*/  0, 10,  7,  5,  5,  5,  7,  4,  0, 10,  7,  5,  5,  5,  7,  4,
    /*2*/  0, 10, 16,  5,  5,  5,  7,  4,  0, 10, 16,  5,  5,  5,  7,  4,
    /*3*/  0, 10, 13,  5, 10, 10, 10,  4,  0, 10, 13,  5,  5,  5,  7,  4,
    /*4*/  5,  5,  5,  5,  5,  5,  7,  5,  5,  5,  5,  5,  5,  5,  7,  5,
    /*5*/  5,  5,  5,  5,  5,  5,  7,  5,  5,  5,  5,  5,  5,  5,  7,  5,
    /*6*/  5,  5,  5,  5,  5,  5,  7,  5,  5,  5,  5,  5,  5,  5,  7,  5,
    /*7*/  7,  7,  7,  7,  7,  7,  7,  7,  5,  5,  5,  5,  5,  5,  7,  5,
    /*8*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*9*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*A*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*B*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*C*/  5, 10, 10, 10, 11, 11,  7, 11,  5, 10, 10,  0, 11, 17,  7, 11,
    /*D*/  5, 10, 10, 10, 11, 11,  7, 11,  5,  0, 10, 10, 11,  0,  7, 11,
    /*E*/  5, 10, 10, 18, 11, 11,  7, 11,  5,  5, 10,  4, 11,  0,  7, 11,
    /*F*/  5, 10, 10,  4, 11, 11,  7, 11,  5,  5, 10,  4, 11,  0,  7, 11
};

g++ 给我带来了这个错误:

8080.h:521:错误:非整型“const unsigned char[256]”的静态数据成员的类内初始化无效

该数组位于名为 i8080 的类中。

I was trying to make a Intel 8080 CPU emulator (then I'd like to emulate Space Invaders, which use it).

I coded nearly complete implementation of this CPU (thanks to MAME and Tickle project (mostly) ;) ) except undocument instructions (0x08, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x0CB, 0x0D9, 0x0DD, 0x0ED, 0x0FD).

I've have only problems when I compile it, I don't know why.

This is the code:

static const unsigned char cycles_table[256] =
{
    /*                       8080's Cycles Table                         */
    /*     0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F */
    /*0*/  4, 10,  7,  5,  5,  5,  7,  4,  0, 10,  7,  5,  5,  5,  7,  4,
    /*1*/  0, 10,  7,  5,  5,  5,  7,  4,  0, 10,  7,  5,  5,  5,  7,  4,
    /*2*/  0, 10, 16,  5,  5,  5,  7,  4,  0, 10, 16,  5,  5,  5,  7,  4,
    /*3*/  0, 10, 13,  5, 10, 10, 10,  4,  0, 10, 13,  5,  5,  5,  7,  4,
    /*4*/  5,  5,  5,  5,  5,  5,  7,  5,  5,  5,  5,  5,  5,  5,  7,  5,
    /*5*/  5,  5,  5,  5,  5,  5,  7,  5,  5,  5,  5,  5,  5,  5,  7,  5,
    /*6*/  5,  5,  5,  5,  5,  5,  7,  5,  5,  5,  5,  5,  5,  5,  7,  5,
    /*7*/  7,  7,  7,  7,  7,  7,  7,  7,  5,  5,  5,  5,  5,  5,  7,  5,
    /*8*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*9*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*A*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*B*/  4,  4,  4,  4,  4,  4,  7,  4,  4,  4,  4,  4,  4,  4,  7,  4,
    /*C*/  5, 10, 10, 10, 11, 11,  7, 11,  5, 10, 10,  0, 11, 17,  7, 11,
    /*D*/  5, 10, 10, 10, 11, 11,  7, 11,  5,  0, 10, 10, 11,  0,  7, 11,
    /*E*/  5, 10, 10, 18, 11, 11,  7, 11,  5,  5, 10,  4, 11,  0,  7, 11,
    /*F*/  5, 10, 10,  4, 11, 11,  7, 11,  5,  5, 10,  4, 11,  0,  7, 11
};

g++ takes me this error:

8080.h:521: error: invalid in-class initialization of static data member of non- integral type `const unsigned char[256]'

This array is in a class called i8080.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水溶 2024-08-26 07:35:45

正如它所说,您不能在类定义中初始化静态非整数类型。也就是说,您可以这样做:

static const unsigned value = 123;
static const bool value_again = true;

但不能执行其他任何操作。

您应该做的是将其放入您的类定义中:

static const unsigned char cycles_table[256];

在相应的源文件中,放置您所拥有的内容:

const unsigned char i8080::cycles_table[256] = // ...

它的作用是(在定义中),“嘿,将会有这个数组。”在源文件中,“嘿,这是那个数组。”

Like it says, you cannot initialize static non-integral types in a class definition. That is, you could do this:

static const unsigned value = 123;
static const bool value_again = true;

But not anything else.

What you should do is place this in your class definition:

static const unsigned char cycles_table[256];

And in the corresponding source file, place what you have:

const unsigned char i8080::cycles_table[256] = // ...

What this does is say (in the definition), "Hey, there's gonna be this array." and in the source file, "Hey, here's that array."

情愿 2024-08-26 07:35:45

静态数据成员需要在类外部初始化。

Static data members need to be initialised outside of the class.

渔村楼浪 2024-08-26 07:35:45

您不能像这样初始化嵌入在类中的静态数组:

class Thing
{
public:
    static const int [3] = {1, 2, 3};
};

您必须这样做:

thing.h:

class Thing
{
public:
    static const int vals[3];;
};

thing.cpp:

const int Thing::vals[3] = {1, 2, 3};

You cannot initialize a static array embedded within a class like this:

class Thing
{
public:
    static const int [3] = {1, 2, 3};
};

You have to do it like this:

thing.h:

class Thing
{
public:
    static const int vals[3];;
};

thing.cpp:

const int Thing::vals[3] = {1, 2, 3};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文