简体   繁体   中英

C++ - error: 'BO3' was not declared in this scope

class BO2Offsets
{
    public:
        struct Prestige
        {
            u32 Offset { 0x000000 };
            char One { 0x01 },
                Two { 0x02 },
                Three { 0x03 },
                Four { 0x04 },
                Five { 0x05 },
                Six { 0x06 },
                Seven { 0x07 },
                Eight { 0x08 },
                Nine { 0x09 },
                Ten { 0x0A },
                MasterPrestige { 0x0B },
                CheatedPrestige { 0x0C };
        };
};
BO2Offsets BO2;

main.c

BO2 *BO3;

I'm creating a new element as BO2 but it's returned me an error:

error: 'BO3' was not declared in this scope

How can I resolve this ?
EDIT: When I declare BO3 like that:

BO2Offsets *BO3;

I use BO3 like this:

BO3->Prestige->Offset

And I'm getting an error: error: invalid use of 'struct BO2Offsets::Prestige'|

You need a typedef there. What you have right now is a variable declaration.

Change BO2Offsets BO2; to typedef BO2Offsets BO2;


As to your second question, you can't use Prestige like that because it is not data member. If you need to access the inner type, you need BO2Offsets::Prestige::Offset

BO2 isn't type, is only variable name, and compiler want type.

use

BO2Offsets * B03;

EDIT: in the second place use

BO3->Prestige.anyName.Offset;

EDIT2; OK folks, if everyone edit his contents, I edit too: struct is improperly introduced, field cannot bee accessed. Now such concept compiles OK on modern GCC. BTW such introduction of Prestige isn't too useful, is similar like 'anonymous class' (to some degree). I allays declare struct / class at higher level. In this fragment can bee omitted.
But give name for field (my anyName ) is important to access his internal fields.

class BO2Offsets
    {
        public:
            struct Prestige
            {
                u32 Offset { 0x000000 };
                char One { 0x01 },
                    Two { 0x02 },
                    Three { 0x03 },
                    Four { 0x04 },
                    Five { 0x05 },
                    Six { 0x06 },
                    Seven { 0x07 },
                    Eight { 0x08 },
                    Nine { 0x09 },
                    Ten { 0x0A },
                    MasterPrestige { 0x0B },
                    CheatedPrestige { 0x0C };
            } anyName; // here !!!
    };

BO3 is nothing in your case.

You need to cast BO3 at first.

BO2Offsets BO3;

or

BO2Offsets *BO3;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM