简体   繁体   中英

Problem with inlining functions gives “Member access into incomplete type” compiler error

I have an issue with implementing inline functions in one of my classes.

I have successfully inlined functions for one of the classes that this class manages as follows:

    static bool filterInfected( Person* p ) { return p->isInfected(); }

the header file for Person is included in this classes.hpp file

BUT

When I try to inline another function for another managed class using a similar protocol:

static int accumulateInfected( GroupHeader* groupHeader ) { return groupHeader->getNumInfected(); }

I get a compiler error "Member access into incomplete type 'GroupHeader'"

As with the Person* above, the header file for GroupHeader is included in this classes.hpp file

If I move the function body out of the heder file into the.cpp source file everything works jut fine, but I have many one-line access functions that I want to inline to remove clutter from the implementation file.

Any help would be greatly appreciated, if you need more information, dont hesitate to ask.

Thanks in anticipation

Terry

Fixed, by including the header file for GroupHeader directly in the header file for GroupMaster. This didn't initially work because the GroupHeader.hpp file was including the GroupMaster.hpp file (there must have been a good reason for this sometime.) deleting this header from the GroupHeader.hpp file fixed my issue and didn't break anything else.

Note to self: Check and re-check all header includes; are they really necessary, or will a forward class declaration suffice?

Thanks to everyone who responded to my initial question.

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