Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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.


C++
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'
Posted
Updated 17-Feb-11 8:48am
v2

1 solution

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

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

    short ARRAYSIZE;
};


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

Or doing this before the class definition:

C++
#undef ARRAYSIZE


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

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

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


That will print 100.
 
Share this answer
 
v3
Comments
23_444 17-Feb-11 15:05pm    
It worked. Thank you. Not sure how ARRAYSIZE is a macro? I just made up the name as the name of the constant and can't find it anywhere in Help. Please tell me more. Thanks again.
Nish Nishant 17-Feb-11 15:09pm    
Updated my answer with more info.
23_444 17-Feb-11 15:11pm    
Thanks, I would have been stuck on that for some time!
Nish Nishant 17-Feb-11 15:12pm    
No problem, you are welcome!
Sergey Alexandrovich Kryukov 17-Feb-11 15:17pm    
Easy enough? My 5,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900