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

confusing behaviour with iterators .net 2003

Hello,

Where it2 is a vector<Body3d>::const_iterator

How come I can't do this
float xd = (*it2).getXpos();

(Which fails with a "error C2662: 'Body3d::getXpos' : cannot convert 'this'
pointer from 'const std::allocator<_Ty>::value_type' to 'Body3d &')

I have to do this to get it to work.
Body3d bd = (*it2);
float xd = db.getXpos();

Seems like a step backwards!
Nov 17 '05 #1
3 740
On Mon, 09 Aug 2004 23:11:07 GMT, Kavvy confounded his critics by
announcing:
Hello,

Where it2 is a vector<Body3d>::const_iterator

How come I can't do this
float xd = (*it2).getXpos();

(Which fails with a "error C2662: 'Body3d::getXpos' : cannot convert 'this'
pointer from 'const std::allocator<_Ty>::value_type' to 'Body3d &')

I have to do this to get it to work.
Body3d bd = (*it2);
float xd = db.getXpos();

Seems like a step backwards!


Ooops!

It needs to be an iterator rather than a constant iterator!
Nov 17 '05 #2
Kavvy wrote:
Hello,

Where it2 is a vector<Body3d>::const_iterator

How come I can't do this
float xd = (*it2).getXpos();

(Which fails with a "error C2662: 'Body3d::getXpos' : cannot convert
'this' pointer from 'const std::allocator<_Ty>::value_type' to
'Body3d &')

I have to do this to get it to work.
Body3d bd = (*it2);
float xd = db.getXpos();

Seems like a step backwards!


It's because Body3d::getXpos() isn't a const member, e.g.

class Body3d
{
// ...
float getXpos() const
{
return ...
}
};

-cd
Nov 17 '05 #3
Kavvy wrote:
On Mon, 09 Aug 2004 23:11:07 GMT, Kavvy confounded his critics by
announcing:
Where it2 is a vector<Body3d>::const_iterator

How come I can't do this
float xd = (*it2).getXpos();

(Which fails with a "error C2662: 'Body3d::getXpos' : cannot convert 'this'
pointer from 'const std::allocator<_Ty>::value_type' to 'Body3d &')


Ooops!

It needs to be an iterator rather than a constant iterator!


A better solution would be to be to make your classes const-correct,
starting by changing getXpos() to be a const member function.

--
David Olsen
qg********@yahoo.com

Nov 17 '05 #4

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

Similar topics

2
by: Alex Martelli | last post by:
Interested parties (essentially, people who write user-coded iterator, or are intense users of iterators as "stream of data", of standard library module itertools, etc) are welcome to read, and...
36
by: Dmitriy Iassenev | last post by:
hi, I found an interesting thing in operator behaviour in C++ : int i=1; printf("%d",i++ + i++); I think the value of the expression "i++ + i++" _must_ be 3, but all the compilers I tested...
48
by: marbac | last post by:
Hi, i heard a lot about "undefined behaviour" in this and other newsgroups dealing with c/c++. Is there a list where all cases with undefined behaviour in C++ are listed? regards marbac
18
by: deancoo | last post by:
I have gotten into the habit of often using copy along with an insert iterator. There are scenarios where I process quite a lot of data this way. Can someone give me a general feel as to how much...
24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
4
by: Wayne Aprato | last post by:
I have a simple database which was originally written in Access 97. When converted to Access 2000 file format it ran flawlessly in Access 2002. I've just tried to run it in Access 2003 and I am...
6
by: Kevin | last post by:
Hi All, Please could someone explain to me what an iterator is and how it may be used in a real world situation. I am new to C#, and I can't find a decent,plain english explanation for...
2
by: ma740988 | last post by:
typedef std::vector < std::complex < double > > complex_vec_type; // option1 int main() { complex_vec_type cc ( 24000 ); complex_vec_type dd ( &cc, &cc ); } versus
8
by: ZikO | last post by:
Hi Are iterators' behaviour the same as pointers? I mean I know i can go through the container with the same manner as if i use pointers (ptr++) and i can derefference iterators the same way. ...
2
by: subramanian100in | last post by:
In ISO/IEC 14882:2003 document, in the section '23.2.1.3 deque modifiers', the following is mentioned: iterator insert(iterator position, const T& x); void insert(iterator position, size_type...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
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....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.