I have defined the following boost::variant type:
#include <boost/variant.hpp>
#include <vector>
#include <string>
struct SharedNodeType;
typedef float TypeA;
typedef int TypeB;
typedef std::string TypeC;
typedef char* TypeD;
typedef boost::variant
<TypeA, TypeB, TypeC, TypeD, SharedNodeType> BaseNodeType;
Where TypeA, TypeB, TypeC, and TypeD are fully qualified, complete types (the exact type is irrelevant, but in this case they are other structs).
And I have defined the following struct:
struct SharedNodeType
{
std::string nodeName;
BaseNodeType node;
};
However, the struct as written above will not compile, giving pages of errors (far too many to include here), mostly related to "incomplete type not allowed."
The very first compiler error is:
In file included from ./apps/iv_parserTest.cc(1):
/opt/common/boost/1.50.py2.7/include/boost/mpl/sizeof.hpp(27): error: incomplete type is not allowed
: mpl::size_t< sizeof(T)>
But, if I change the struct to the following, it compiles without a problem:
struct SharedNodeType {
std::string nodeName;
std::vector<BaseNodeType> node;
};
Since my SharedNodeType
will never have more than one node, this seems wasteful to me.
Why is it that the second form of the struct will compile, but the first form will not?
EDIT:
After experimenting some more, I have determined the problem appears to be in the fact that the BaseNodeType variant type also contains SharedNodeType. I have updated my code example accordingly, but it still leaves the question of why the compiler is able to resolve the types if they're inside a std::vector
but not otherwise.