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

stl vector help

if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?

I get is:
main.cpp: In function `int main()':
main.cpp:75: error: base operand of `->' has non-pointer type `Car'


Sep 16 '05 #1
8 1679
* Greg:
if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?


Possibly because Car doesn't define operator->() ... ;-)

Try

*(cari).printDetails();

or

cari->printDetails();

but not both.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 16 '05 #2
* Alf P. Steinbach:
* Greg:
if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?
Possibly because Car doesn't define operator->() ... ;-)

Try

*(cari).printDetails();


Typo (my fingers aped what my eyes saw, I have little control over all these
semi-autonomous subsystems),

(*cari).printDetails();

or

cari->printDetails();

but not both.


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 16 '05 #3
Alf P. Steinbach wrote:
* Alf P. Steinbach:
* Greg:
if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?


Possibly because Car doesn't define operator->() ... ;-)

Try

*(cari).printDetails();

Typo (my fingers aped what my eyes saw, I have little control over all these
semi-autonomous subsystems),

(*cari).printDetails();

Alf, it's a vector of Car*, so it should be

(*cari)->printDetails();

Sep 16 '05 #4
Alf P. Steinbach wrote:
* Greg:
if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?

Possibly because Car doesn't define operator->() ... ;-)

Try

*(cari).printDetails();

or

cari->printDetails();

but not both.


Huh?
I would say:

(*cari)->printDetails();

Since the vector holds Car*.
Or am I missing something?
Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de
Sep 16 '05 #5
Greg wrote:
if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?


(*cari)->printDetails();

john
Sep 16 '05 #6
* red floyd:
Alf P. Steinbach wrote:
* Alf P. Steinbach:
* Greg:

if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?

Possibly because Car doesn't define operator->() ... ;-)

Try

*(cari).printDetails();

Typo (my fingers aped what my eyes saw, I have little control over all these
semi-autonomous subsystems),

(*cari).printDetails();

Alf, it's a vector of Car*


Oops.

, so it should be

(*cari)->printDetails();


Yep. Thanks.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Sep 16 '05 #7
Alf P. Steinbach wrote:
* Alf P. Steinbach:
* Greg:
> if I have:
>
>
> vector<Car*> car;
>
> vector<Car*>::iterator cari;
> for(cari = car.begin(); cari != car.end(); cari++)
> {
> *(cari)->printDetails();
> }
>
> where printDetails() is a function in class Car why can I not comple
> this code the error?
.... Typo (my fingers aped what my eyes saw, I have little control over all
these semi-autonomous subsystems),

(*cari).printDetails();
or
cari->printDetails();

but not both.


Of course both, as the element-type of vector is a pointer.
But write
(*cari)->printDetails();

Sep 16 '05 #8
Greg wrote:
if I have:
vector<Car*> car;

vector<Car*>::iterator cari;
for(cari = car.begin(); cari != car.end(); cari++)
{
*(cari)->printDetails();
}

where printDetails() is a function in class Car why can I not comple this
code the error?

I get is:
main.cpp: In function `int main()':
main.cpp:75: error: base operand of `->' has non-pointer type `Car'

It might be easier to avoid this kind of errors if you did it in steps:
vector<Car*>::iterator cari;
for (cari = car.begin(); cari != car.end(); ++cari)
{
Car* carp = *cari;
carp->printDetails();
}
Sep 17 '05 #9

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

Similar topics

4
by: Jessica | last post by:
Hi, I do not have a lot of experience with STL and I hope some of you might be able to help me on this seemingly elementary question. I have a vector of doubles (v1). I am trying to copy the...
4
by: wukexin | last post by:
I try some kind of compiler, my program compile succeeding, but run wrongly. Help me, see my program. If you have free time, please give me some suggestion about process command argument. Thank you...
9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
11
by: Steve | last post by:
Hi, I'm using a std::vector to store a list of user defined objects. The vector may have well over 1000 elements, and I'm suffering a performance hit. If I use push_back I get a much worse...
6
by: kittykat | last post by:
Hello, I am writing a program that will read each line of a file into a vector of vectors. This data will then be analysed. Here is what i have done: typedef vector<string> lines; ......
10
by: gogogo_1001 | last post by:
Dear all, I don't understand why "delete" works well on destructing a object, but fails to destruct a vector of it. Any of your comment is highly appreciated! Following is the program...
1
by: raylegendkiller | last post by:
NEED TO MAKE A PROGRAM which computes the current value of the vectors {x} based on the following forward iterations: this >>> {x}(n+1) = {x}(n), n = 0,1,2, ... ,8,9. In other...
10
by: JDT | last post by:
Hi, Can someone provide me an example that uses std::max_element() (probablly the predicate version) to return the max "absolute" integer in a vector? Your help is much appreciated. Tony ...
32
by: T. Crane | last post by:
Hi, I'm struggling with how to initialize a vector<vector<double>> object. I'm pulling data out of a file and storing it in the vector<vector<double>object. Because any given file will have a...
0
by: doobybug | last post by:
Hi all, I really need your help! I am new to java and have some problems with my code. I have a program which inputs questionnaires and creates an object for each questionnaire. These objects are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.