Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > What does 'illegal indirection' mean?

Reply
Thread Tools

What does 'illegal indirection' mean?

 
 
Lambda
Guest
Posts: n/a
 
      05-16-2008
The code is simple:

// Token.h
#ifndef TOKEN_H
#define TOKEN_H

#include <vector>
#include <string>

class Token
{
public:
Token() : type("word"), positionIncrement(1), startOffset(0),
endOffset(0) {}
void setPositionIncrement(const unsigned int increment)
{
positionIncrement = increment;
}
unsigned int getPositionIncrement() const
{
return positionIncrement;
}
void setTermBuffer(const std::vector<char>::size_type&,
const std::vector<char>::size_type&);
private:
std::vector<char> termBuffer;
std::vector<char> payload;

unsigned int startOffset;
unsigned int endOffset;

std::string type;
unsigned int positionIncrement;
};

#endif

// Token.cpp
#include <algorithm>
#include <iterator>

#include "Token.h"

using std::copy;
using std::back_inserter;

void Token::setTermBuffer(const std::vector<char>::size_type& b,
const std::vector<char>::size_type& e)
{
copy(b, e, back_inserter(termBuffer));
}

The setTermBuffer function is used to copy a vector into the
termBuffer vector.
But I got an error: 'error C2100: illegal indirection'
What does it mean?

BTW, as I include <vector> in the header file,
the cpp file include the header, need I add '#include <vector>' the
cpp file?

Best Regards,
Lambda
 
Reply With Quote
 
 
 
 
Lambda
Guest
Posts: n/a
 
      05-16-2008
On May 16, 10:13 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
> Lambda wrote:
> > The code is simple:

>
> > // Token.h
> > #ifndef TOKEN_H
> > #define TOKEN_H

>
> > #include <vector>
> > #include <string>

>
> > class Token
> > {
> > public:
> > Token() : type("word"), positionIncrement(1), startOffset(0),
> > endOffset(0) {}
> > void setPositionIncrement(const unsigned int increment)
> > {
> > positionIncrement = increment;
> > }
> > unsigned int getPositionIncrement() const
> > {
> > return positionIncrement;
> > }
> > void setTermBuffer(const std::vector<char>::size_type&,
> > const std::vector<char>::size_type&);
> > private:
> > std::vector<char> termBuffer;
> > std::vector<char> payload;

>
> > unsigned int startOffset;
> > unsigned int endOffset;

>
> > std::string type;
> > unsigned int positionIncrement;
> > };

>
> > #endif

>
> > // Token.cpp
> > #include <algorithm>
> > #include <iterator>

>
> > #include "Token.h"

>
> > using std::copy;
> > using std::back_inserter;

>
> > void Token::setTermBuffer(const std::vector<char>::size_type& b,
> > const std::vector<char>::size_type& e)
> > {
> > copy(b, e, back_inserter(termBuffer));
> > }

>
> > The setTermBuffer function is used to copy a vector

>
> Which vector does it copy?
>
> > into the

>
> > termBuffer vector.
> > But I got an error: 'error C2100: illegal indirection'
> > What does it mean?

>
> It usually means you're trying to use an object that does not support
> the operator* (dereferencing) in the context that requires it. For
> example, here the 'copy' function (template) actually does approximately
> this:
>
> // copy(a, b, blah)
> while (a != b) {
> *blah = *a; // line 12345
> ++a;
> ++blah;
> }
>
> Now, since you have 'b' and 'e' declared as 'size_type' (which is just
> an integral unsigned type, like 'unsigned' or 'size_t'), you cannot
> dereference it (apply the operator* to it, see line 12345).
>
> Now, what you probably intended is to copy the elements of some other
> vector between the indices 'b' and 'e', and since 'copy' expects
> something that implements the semantics of an iterator, you need to
> convert your indices into iterators. However, the function does not
> have the "source" vector reference or pointer. How the hell would the
> function know where to get those elements?
>
> It would be better if you defined your 'setTermBuffer' as a template
> (basically a wrapper around the 'copy' template):
>
> template<class It> void setTermBuffer(It b, It e) {
> std::copy(b, e, std::back_inserter(termBuffer));
> }
>
> When you call it, pass the *iterators* as the start and end, not indices
> because the iterators know what container they iterate, but indices are
> dumb in that sense.
>
>
>
> > BTW, as I include <vector> in the header file,
> > the cpp file include the header, need I add '#include <vector>' the
> > cpp file?

>
> The rule of thumb is that every module (and a C++ source file is one,
> and a C++ header file is one as well) that uses a symbol defined
> elsewhere, should include the necessary header. So, IMNSHO, yes, you do
> need to include <vector> in the 'cpp' file *regardless* of whether you
> include it into your other header, because if you don't, you create an
> unnecessary dependency between the header and the C++ file (on top of
> other dependencies that already exist between them).
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask


Thank you, Victor.

Yes, I intended to use iterator.
I focused on the error, didn't note i used size_type.

And I'll take your suggestion on 'include'.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
.NET 2.0 ASPx Page does not load, but HTM does prabhupr@hotmail.com ASP .Net 1 02-08-2006 12:57 PM
Button OnClick does not fire on first postback, but does on second Janet Collins ASP .Net 0 01-13-2006 10:08 PM
Does the 2.0 Framework come out when Visual Studio .NET 2005 does? needin4mation@gmail.com ASP .Net 3 10-07-2005 12:55 AM
CS0234 Global does not exist ... but it genuinely does Bill Johnson ASP .Net 0 07-08-2005 06:34 PM
Does no one else think microsoft does a poor job? =?Utf-8?B?SmVyZW15IEx1bmRncmVu?= Wireless Networking 2 11-20-2004 12:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57