Here's a gentle program that completely rapes my compiler. How is span an incomplete type?
Code:
#include <vector>
#include <iostream>
class grid
{
public:
struct span
{
int x; int y; int dy;
};
typedef std::vector<span> region;
};
class thread_method
{
public:
grid::region & region(std::vector<grid::region>::size_t index) = 0;
};
class single_thread : public thread_method
{
grid::region r;
public:
grid::region & region(std::vector<grid::region>::size_t index) { return r; }
};
int main()
{
thread_method * tmeth = new single_thread();
std::cout << tmeth->region(0).size() << std::endl;
delete tmeth;
}
Code:
david@david-laptop:~/Desktop$ g++ prob.cpp -o prob
prob.cpp:19: error: expected ‘;’ before ‘(’ token
prob.cpp:26: error: expected ‘;’ before ‘(’ token
prob.cpp:27: error: expected `;' before ‘}’ token
prob.cpp: In function ‘int main()’:
prob.cpp:32: error: ‘class thread_method’ has no member named ‘region’
/usr/include/c++/4.2/bits/stl_vector.h: In destructor ‘std::_Vector_base<_Tp, _Alloc>::~_Vector_base() [with _Tp = grid::span, _Alloc = std::allocator<grid::span>]’:
/usr/include/c++/4.2/bits/stl_vector.h:199: instantiated from ‘std::vector<_Tp, _Alloc>::vector(const _Alloc&) [with _Tp = grid::span, _Alloc = std::allocator<grid::span>]’
prob.cpp:23: instantiated from here
/usr/include/c++/4.2/bits/stl_vector.h:120: error: invalid use of incomplete type ‘struct grid::span’
prob.cpp:7: error: forward declaration of ‘struct grid::span’
/usr/include/c++/4.2/bits/stl_construct.h: In function ‘void std::__destroy_aux(_ForwardIterator, _ForwardIterator, std::__false_type) [with _ForwardIterator = grid::span*]’:
/usr/include/c++/4.2/bits/stl_construct.h:155: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = grid::span*]’
/usr/include/c++/4.2/bits/stl_construct.h:182: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>) [with _ForwardIterator = grid::span*, _Tp = grid::span]’
/usr/include/c++/4.2/bits/stl_vector.h:268: instantiated from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = grid::span, _Alloc = std::allocator<grid::span>]’
prob.cpp:23: instantiated from here
/usr/include/c++/4.2/bits/stl_construct.h:121: error: cannot increment a pointer to incomplete type ‘grid::span’
/usr/include/c++/4.2/bits/stl_construct.h: In function ‘void std::_Destroy(_Tp*) [with _Tp = grid::span]’:
/usr/include/c++/4.2/bits/stl_construct.h:122: instantiated from ‘void std::__destroy_aux(_ForwardIterator, _ForwardIterator, std::__false_type) [with _ForwardIterator = grid::span*]’
/usr/include/c++/4.2/bits/stl_construct.h:155: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = grid::span*]’
/usr/include/c++/4.2/bits/stl_construct.h:182: instantiated from ‘void std::_Destroy(_ForwardIterator, _ForwardIterator, std::allocator<_T2>) [with _ForwardIterator = grid::span*, _Tp = grid::span]’
/usr/include/c++/4.2/bits/stl_vector.h:268: instantiated from ‘std::vector<_Tp, _Alloc>::~vector() [with _Tp = grid::span, _Alloc = std::allocator<grid::span>]’
prob.cpp:23: instantiated from here
/usr/include/c++/4.2/bits/stl_construct.h:107: error: invalid use of incomplete type ‘struct grid::span’
prob.cpp:7: error: forward declaration of ‘struct grid::span’
david@david-laptop:~/Desktop$