Problem with deque

Started by
14 comments, last by Tybon 19 years, 3 months ago
Tybon - Fruny's code does not compile for me on VS.NET 03 either.
c:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\deque(62): error C2027: use of undefined type 'Q'        c:\Documents and Settings\SpicyMC\My Documents\test2\main.cpp(6) : see declaration of 'Q'

-------------------------Rayoom Sledge Hammer Productions - Programmer
Advertisement
Okay then it must be Micro$oft's fault. Some how Visual Studio .Net 2003's C++ compiler has problem with the queue family of class templates. Very gay...

This compiles fine:

class V{    static std::vector<V> v;};


Yet, this does not compile:

class Q{    static std::deque<Q> q;};
It could simply be that MSVC 2003 implements deque (and other queue classes) in such a way were you can't use a partially defined types without generating a compile error, by whatever internal rule it uses.

Oh, and Micro$oft. I've never heard that one before. The cleverness has stupefied me to the point where it isn't funny, just tired and cliché. Weird.
IIRC, the standard only mentions this behavior in reference to std::vector, allowing class T to contain a std::vector of class T. The other container types are not defined, I think (which would leave them implementation dependent).
daerid@gmail.com
Quote:Original post by Tybon
If I have to hold pointers in my priority_queue, how are the comparisons done? Does it compare the pointers (which is not what I want) or the objects themselves?


if you checked documentation you would see that priority_queue is also parameterized by comparator type which defaults to std::less<T> allowing you to provide a custom comparator type be it free/member function or a functor you do something like this:

struct Q_Less {    bool operator()(const Q* const a, const Q* const b) const {             return /* some comparisons */    }};typedef std::priority_queue< Q*, std::vector<Q*>, Q_Less > pq_of_Qs;


Quote:Original post by Tybon
Some how Visual Studio .Net 2003's C++ compiler has problem with the queue family of class templates.


if you actually checked vc++ 2k3's deque you would see what line is giving you problems:

template< class _Ty,	 class _Ax >class deque : public _Deque_val<_Ty, _Ax> {public:    enum { _DEQUESIZ = _DEQUESIZ_VALUE };//..


where _DEQUESIZ_VALUE is defined to be:

#define _DEQUESIZ_VALUE	(sizeof (_Ty) <= 1 ? 16                       : sizeof (_Ty) <= 2 ? 8                       : sizeof (_Ty) <= 4 ? 4                       : sizeof (_Ty) <= 8 ? 2 : 1) /* elements per block (a power of 2) */


There for the type parameter _Ty needs to be fully defined at compile-time regardless of making it class/static member or not.

Either you change what the value of _DEQUESIZ is, or you store (smart) pointers to Q, or you do template specialization for Q, or you download a different implementation of STL (something like STLport), or you try a different container.

If i was you i would go for just storing smart pointers to Q this will give you expected behaviour on all different compiler implementations of STL not just vc++ 2k3.
Thanks for the suggestions snk_kid. At least I now know why the problem is happening and have some options.

This topic is closed to new replies.

Advertisement