Click here to Skip to main content
14,175,219 members
Rate this:
Please Sign up or sign in to 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.

class CRsSortPPage : public CPropertyPage{

    const unsigned short ARRAYSIZE;


    : CPropertyPage(CRsSortPPage::IDD),

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

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

class Test
    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:



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

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

That will print 100.
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,
Nish Nishant 17-Feb-11 15:20pm
Thank you, SA!
Espen Harlinn 17-Feb-11 18:32pm
Nicely spotted, my 5 :)
Nish Nishant 17-Feb-11 19:22pm
Thanks Espen.
Albert Holguin 17-Feb-11 22:47pm
typically names with all capitals are used for macros/definitions, to avoid this in the future, don't use all capital names for variables... its probably not a good idea to #undef a macro if you didn't define it in the first place
Albert Holguin 17-Feb-11 22:48pm
...and good catch for nishant...

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web03 | 2.8.190524.3 | Last Updated 17 Feb 2011
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100