There is an interesting observation. Both GCC5.2 and CLANG3.6 compile the following code.
struct A; std::vector<A> my_func();
But throw errors for
struct A; std::vector<A> v;
And the argument for this is that the size of the vector will not change for the other type that it holds. See the following code snippet.
struct B{int i; int j;}; struct C{int a,b,c;}; std::vector<B> pp; std::vector<C> qq; int main() { std::cout<<sizeof(pp)<<'\n'; std::cout<<sizeof(qq)<<'\n'; }
Exit
24 24
But for std::vector<A> v it should also provide Allocator<A>() . And the distributor needs members of the struct A constructor like the constructor, copy constructor, destructor, etc. It is also important to note here pointer arithmetic for incomplete type is not allowed.
If you see errors released by CLANG, this clearly says the same thing.
In file included from /tmp/gcc-explorer-compiler115920-68-1xsb8x7/example.cpp:2: In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/vector:64: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_vector.h:161:9: error: arithmetic on a pointer to an incomplete type 'A' - this->_M_impl._M_start); } ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_vector.h:253:7: note: in instantiation of member function 'std::_Vector_base<A, std::allocator<A> >::~_Vector_base' requested here vector() ^
Everything else is pretty straight forward.
The following is an example of typedef, so the compiler needs to know about size.
using abc_vector = std::vector<abc>;
So, the code structure in question is good to continue.
source share