Thread: std::deque help...

  1. #1
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Banks of the River Styx

    std::deque help...

    Edit: Solved. Posted, saw the "const" in the error, and then it hit me: const. Peek() is const (as peeking a buffer shouldn't change it). Change the iterator to a const_iterator, and everything works. Good day, thank you CBoard for sparking my mind.. (That's what I get for trying to be const-correct...)
    Edit II: Sorry for the ... width ... of the original post.

    Can't seem to get iterators for deques working. This is probably a simple error somewhere. Sorry about the length - tried to make a smaller example but it worked. (And I've no clue how it differs...)
    The sole error perplexing me:
    BufferImpl.cpp: In member function `unsigned int Net::BufferImpl::Peek(void*, unsigned int, unsigned int) const':
    BufferImpl.cpp:90: error: no match for 'operator=' in
      'i = (((const std::deque<Net::DataChunk, std::allocator<Net::DataChunk> >*)
        ((const Net::BufferImpl*)this)) + 4u)->std::deque<_Tp, _Alloc>::begin
      [with _Tp = Net::DataChunk, _Alloc = std::allocator<Net::DataChunk>]()'
    N:/MINGW/include/c++/3.4.2/bits/stl_deque.h:101: note:
      candidates are:
      std::_Deque_iterator<Net::DataChunk, Net::DataChunk&, Net::DataChunk*>& 
      std::_Deque_iterator<Net::DataChunk, Net::DataChunk&, Net::DataChunk*>::operator=
        (const std::_Deque_iterator<Net::DataChunk, Net::DataChunk&, Net::DataChunk*>&)
    Header file:
    #ifndef _INET_PIMPL_H
    #define _INET_PIMPL_H
    #include <stdint.h>
    #include <deque>
    #include <boost/shared_array.hpp>
    namespace Net
    	struct DataChunk
    		// Snipped
    	class BufferImpl
    		std::deque<DataChunk> m_datalist;
    		BufferImpl(const BufferImpl &b);
    		virtual ~BufferImpl();
    		BufferImpl &operator = (const BufferImpl &b);
    		unsigned int Read(void *buffer, unsigned int length);
    		unsigned int Write(const void *buffer, unsigned int length);
    		unsigned int Peek(void *buffer, unsigned int length, unsigned int pos = 0) const;
    		unsigned int Pop(unsigned int length);
    		unsigned int GetSize() const;
    Code file:
    #include <stdint.h>
    #include <string.h>	// For memcpy()
    #include <deque>
    #include <boost/shared_array.hpp>
    #include "inet_pimpl.h"
    using namespace Net;
    // Snip
    unsigned int BufferImpl::Peek(void *buffer, unsigned int length, unsigned int pos) const
    	uint8_t *ubuf = (uint8_t *) buffer;
    	unsigned int read = 0, seeked = 0;
    	std::deque<DataChunk>::iterator i;
    	for(i = m_datalist.begin(); i != m_datalist.end(); ++i)
    		if(seeked < pos)
    			// Are we at our chunk yet?
    			seeked += (*i).GetDataSize();
    			if(seeked <= pos) continue;
    			// We're done seeking, but _some_ data in this chunk must be copied.
    			// (We've "ought seeked")
    			read = (*i).Peek(ubuf, length, pos - (seeked - (*i).GetDataSize()));
    			// Continue reading
    			read += (*i).Peek(ubuf + read, length - read);
    	return read;
    // Snip
    Last edited by Cactus_Hugger; 11-25-2006 at 09:16 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "error: incomplete type is not allowed"
    By Fahrenheit in forum C++ Programming
    Replies: 9
    Last Post: 05-10-2005, 10:52 PM
Website Security Test