GCC: Array type has incomplete element type

It’s the array that’s causing trouble in: void print_graph(g_node graph_node[], double weight[][], int nodes); The second and subsequent dimensions must be given: void print_graph(g_node graph_node[], double weight[][32], int nodes); Or you can just give a pointer to pointer: void print_graph(g_node graph_node[], double **weight, int nodes); However, although they look similar, those are very different internally. … Read more

Does the GotW #101 “solution” actually solve anything?

You are correct; the example seems to be missing an explicit template instantiation. When I try to run the example with a constructor and destructor for widget::impl on MSVC 2010 SP1, I get a linker error for pimpl<widget::impl>::pimpl() and pimpl<widget::impl>::~pimpl(). When I add template class pimpl<widget::impl>;, it links fine. In other words, GotW #101 eliminates … Read more

How can I declare a member vector of the same class?

This paper was adopted into C++17 which allows incomplete types to be used in certain STL containers. Prior to that, it was Undefined Behavior. To quote from the paper: Based on the discussion on the Issaquah meeting, we achieved the consensus to proceed* with the approach – “Containers of Incomplete Types”, but limit the scope … Read more

Can standard container templates be instantiated with incomplete types?

Here’s my attempt at an interpretation: The standard simply says you mustn’t do this, even though any given concrete implementation may have no problem supporting such a construction. But imagine for example if someone wanted to write a “small vector” optimization by which a vector always contains space for, say, five elements. Immediately you’d be … Read more

Why C++ containers don’t allow incomplete types?

Matt Austern, the chair of the C++ standardization committee’s library working group, explained this decision of the committee in his Dr. Dobb’s article by historical reasons: We discovered, with more testing, that even the [simple] example didn’t work with every STL implementation. In the end, it all seemed too murky and too poorly understood; the … Read more

std::unique_ptr with an incomplete type won’t compile

Here are some examples of std::unique_ptr with incomplete types. The problem lies in destruction. If you use pimpl with unique_ptr, you need to declare a destructor: class foo { class impl; std::unique_ptr<impl> impl_; public: foo(); // You may need a def. constructor to be defined elsewhere ~foo(); // Implement (with {}, or with = default;) … Read more

tech