473,320 Members | 1,775 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,320 software developers and data experts.

Weird error.

Hi,

Does anyone know why the top example is OK, but the bottom one gives a warning ?

void X()

{

void * p;



// This is OK ...

std::vector<int> int_v;

std::vector<int>::iterator int_i;

p = (void *) &( *(int_v.begin() + 5) );



// This gives : warning C4238: nonstandard extension used : class rvalue used as lvalue

std::vector<bool> bool_v;

std::vector<bool>::iterator bool_i;

p = (void *) &( *(bool_v.begin() + 5) );

}

Cheers,

Adam.

--
===========================
Adam Benson
Omnibus Systems,
Leics. UK
Email : Ad*********@NOSPAM.omnibus.co.uk
Nov 17 '05 #1
3 1225
Adam Benson wrote:
Does anyone know why the top example is OK, but the bottom one gives a
warning ?


Because vector<bool> is not an STL container. It should have been called
bitvector or something. I know this is very confusing, but this is what
we have to live with. As odd as it looks, you can't store bools in a
vector. Use deque<bool> instead.

Tom
Nov 17 '05 #2
Hi,

Does anyone know why the top example is OK, but the bottom one gives a warning ?

void X()

{

void * p;

// This is OK ...

std::vector<int> int_v;

std::vector<int>::iterator int_i;

p = (void *) &( *(int_v.begin() + 5) );

// This gives : warning C4238: nonstandard extension used : class rvalue used as lvalue

std::vector<bool> bool_v;

std::vector<bool>::iterator bool_i;

p = (void *) &( *(bool_v.begin() + 5) );

}

Cheers,

Adam.

--
===========================
Adam Benson
Omnibus Systems,
Leics. UK
Email : Ad*********@NOSPAM.omnibus.co

Hi Adam,
Please refer to this article
http://www.gotw.ca/publications/N1185.pdf

Basically, the implementation of std::vector<bool> is in the form of
bitfields. When you add 5 to the iterator and dereference the vector<bool>,
you are actually pointing to the 5th "bit" in the byte.
Then you take an address of that, which is not correct. In order to take the
address you must be at the byte boundary and not at the bit boundary.

So, in short try to avoid using vector<bool> as it is non conformant as you
will read from the article I mentioned.

Thanks,
Kapil Khosla

Nov 17 '05 #3
Thanks for the responses.

I thought I was going nuts.

AB

===========================
Adam Benson
Omnibus Systems,
Leics. UK
Email : Ad*********@NOSPAM.omnibus.co.uk
Nov 17 '05 #4

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

Similar topics

3
by: redneck_kiwi | last post by:
Hi all: I have a really weird problem. I am developing a customer catalog system for my company and as such have delved into sessions for authentication and access levels. So far, I have managed...
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
1
by: amit | last post by:
I am trying to compile the sample program genwin.sqc, using nsqlprep which is used to precompile embedded sql in C. I am getting weird errors and that is because windows.h is included in the...
2
by: Kathy Houtami | last post by:
Hi there I've been encountered with weird compile error using Access 97. The error message is "Member or data member is not found" and it highlighted a line of code that has not be changed and...
6
by: gh0st54 | last post by:
Hi I have a weird javascript error that only happens on my live server when i open the page http://www.imrated.co.uk/reg.aspx i get the error 'Problems with this page ... blablabla Line : 3...
0
by: Alan Silver | last post by:
Hello, I have two weird problems here. I have a master page file that works absolutely fine. When I load it up in VWD, I get a couple of weird (to me) errors. First, I get the error...
0
by: P Pulkkinen | last post by:
Dear all, sorry, i know this code is far little too long to debug here, but there is really annoying logical error. If someone debugs this, I really offer warm virtual handshake. What this...
7
by: dtschoepe | last post by:
Hi, I am working on a project for school and I am trying to get my head around something weird. I have a function setup which is used to get an input from stdin and a piece of memory is created...
6
by: =?Utf-8?B?amVmZmVyeQ==?= | last post by:
i need help with a combo box and this same code works on my first tab with a combo box. The error or problem i have is this code causes an index out of range error when i run it on my second combo...
4
by: d3vkit | last post by:
I recently had a friend pass along some web work for me; a simple update. I for some reason decided I would do some overhauling of the page (he had been doing straight html and I figured some php...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.