c++ - Visual Studio 2010 Express couldn't compile code with cross reference -


gcc can compile code below vs2010 express couldn't:

#include <iostream> #include <queue> using namespace std;  struct {   deque<a>::iterator next; }; int main() {   a; } 

error message:

error c2027: use of undefined type 'a' main.cpp(6) : see declaration of 'a' main.cpp(7) : see reference class template instantiation 'std::deque<_ty>' being compiled 1> 1> [ 1> _ty=a 1> ]

is there way solve problem except using pointers?

as discussed example in how come can use forward-declared class in std::vector?, instantiating standard containers incomplete types undefined behaviour. able access iterator type of std::deque<a>, required instantiate class, program give has undefined behaviour. in specific instance, in gcc undefined behaviour happens expect, while visual studio (with dinkumware standard library implementation) happens fail compile. visual studio behaves different in debug , release mode, in debug mode, containers (and iterators) more complex able check many iterator abuses.

i unable find reference declaring pointer deque iterator element type incomplete type allowed, , afraid replacing iterator pointer iterator not make program defined (although might make work in more environments). if replace iterator pointer: surely work. can't tell whether it's solution, didn't state problem try solve. possibly there different design approach problem doesn't require member variable.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -