简体   繁体   中英

Problems with void function in header of my static library

I'm programming a .lib file for mobile robot. Among other commands regarding robot movement, I also have command for scanning for Bluetooth devices looking something like:

void ScanForDevices(vector<Device> &Robot)
{
    /* code for searching Bluetooth devices and saving their names and addresses into vector of Device struct*/
}

My question is related with writing the header of the .lib file.

One of my commands is:

string RobotMove(int Translation, int Rotation)
    {
            /* create Command
        return string(Command);
    }

In the header, for that command I have:

// Returns MOVE command
        std::string RobotMove(int Translation, int Rotation);

What I have problem with is what to write in the header for:

void ScanForDevices(vector<Device> &Robot)

I keep getting "Incomplete type is not allowed" is I try to do the same way as RobotMove command. Do I have to declare in some way in the header struct Device?

Do I have to declare in some way in the header struct Device?

If you want to create vectors for Device s, you need to let compiler know the size of the class by defining it. As noted by BoBTFish, the usual way is to just include Device.h header (or similar).

If you use pointers ( vector<Device*> or even better, appropriate kind of smart pointer: vector<shared_ptr<Device>> ) forward declaration (just stating class Device; ) would be enough, as compiler knows size of the pointer on your architecture. (Note that this is completely different approach with different semantics than in your question, and this is just a side-note).

if your header file does not include (directly or indirectly),a definition for vector class you need to add #include <vector> to your header file. The compiler does not know this data type without providing it the right information.

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