初始化错误-过时的C ++构造函数初始化语法 [英] initialization error- obsolete C++ constructor initialization syntax

查看:163
本文介绍了初始化错误-过时的C ++构造函数初始化语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误消息说我需要在构造函数基本/成员初始化列表中初始化ARRAYSIZE.我有.不知道为什么我得到错误.任何帮助,将不胜感激.谢谢.


The error message says I need to initialize ARRAYSIZE in constructor base/member initializer list. I have. Not sure why I am getting the error. Any help would be appreciated. Thanks.


class CRsSortPPage : public CPropertyPage{

public:
    const unsigned short ARRAYSIZE;


}


CRsSortPPage::CRsSortPPage()
    : CPropertyPage(CRsSortPPage::IDD),
    ARRAYSIZE(5)
{
}

Error Message

 error C2351: obsolete C++ constructor initialization syntax
 error C2758: 'CRsSortPPage::ARRAYSIZE' : must be initialized in constructor base/member initializer list
 see declaration of 'CRsSortPPage::ARRAYSIZE'

推荐答案

ARRAYSIZE 是宏.这就是为什么您会得到错误.以下代码将给出相同的错误:

ARRAYSIZE is a macro. That''s why you get the error. The following code will give the same error:

class Test
{
public:
    Test()  : ARRAYSIZE(0)
    {
    }

    short ARRAYSIZE;
};



您可以通过将ARRAYSIZE 重命名为其他名称(也许是ARRSIZE)来解决此问题?

或在类定义之前执行以下操作:



You can fix this by either renaming ARRAYSIZE to something else, maybe ARRSIZE?

Or doing this before the class definition:

#undef ARRAYSIZE



[更新]
~~~~~~~~~

为了回应您的评论,以下是ARRAYSIZE的用法.



[Update]
~~~~~~~~~

In response to your comment, here''s how ARRAYSIZE is used.

int test[100];
cout << ARRAYSIZE(test) << endl;



那将显示100.



That will print 100.


这篇关于初始化错误-过时的C ++构造函数初始化语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆