473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What does 'illegal indirection' mean?

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<chartermBuffer;
std::vector<charpayload;

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 <vectorin the header file,
the cpp file include the header, need I add '#include <vector>' the
cpp file?

Best Regards,
Lambda
Jun 27 '08 #1
2 13019
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<chartermBuffer;
std::vector<charpayload;

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 Itvoid 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 <vectorin 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 <vectorin 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
Jun 27 '08 #2
On May 16, 10:13 pm, Victor Bazarov <v.Abaza...@comAcast.netwrote:
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<chartermBuffer;
std::vector<charpayload;
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 Itvoid 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 <vectorin 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 <vectorin 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'.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve Richter | last post by:
What does the "." mean in the following sql script stmts? use GO if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id,N'IsUserTable') = 1) drop table ....
3
by: RobertTG | last post by:
Someone please translate the code below into English... Particularly the indicated line Thanks function attachComment() { var aForms = document.getElementsByTagName("FORM"); for (var i = 0;...
6
by: allenj | last post by:
DB21085I Instance "md" uses "32" bits and DB2 code release "SQL08012" with level identifier "02030106". Informational tokens are "DB2 v8.1.0.16", "s030508", "MI00048", and FixPak "2". Product is...
58
by: Larry David | last post by:
Ok, first of all, let's get the obvious stuff out of the way. I'm an idiot. So please indulge me for a moment. Consider it an act of "community service".... What does "64bit" mean to your friendly...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
45
by: loudking | last post by:
Hello, all I don't quite understand what does ((time_t)-1) mean when I execute "man 2 time" RETURN VALUE On success, the value of time in seconds since the Epoch is retu rned. On error,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.