I'm trying to get the following to compile. However whatever various configurations I try, the compiler doesn't like the fact that I've got a struct defined inside the derived struct that is being referenced in the base struct. Is there any way to resolve this without moving the item struct outside of the derived struct?
#include <vector>
template <typename T>
struct BaseTask
{
int id;
std::vector<typename T::Item> items; // <---- invalid use of incomplete type 'struct DerivedTask'
typename T::Item* GetItemById(int id) // <---- invalid use of incomplete type 'struct DerivedTask'
{
for (auto item : items)
{
if (item.id == id)
{
return &item;
}
}
return nullptr;
}
};
struct DerivedTask : public BaseTask<DerivedTask>
{
struct Item
{
int id;
};
int specialDerivedValue;
};
I've tried forward declaring both the derived struct and the substruct. I've tried forward declaring BaseTask and then defining it at the bottom of the file. Thanks for taking the time to read.