3 Replies - 5463 Views - Last Post: 23 April 2009 - 08:52 PM Rate Topic: -----

#1 isale8888  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 45
  • Joined: 29-October 08

I'm getting an error for no match for operator

Post icon  Posted 22 April 2009 - 09:08 PM

Hi guys

so this is the code

#include<iostream>
#include <vector>
using namespace std;
#include "automobile.h"
#include "truck.h"

int main()
{
   vector<Automobile> garage;

   Automobile  directorCar("Chevrolet", 8, 2007, "maroon",
						   "Steven Spielberg", "987-6543",
						   "Corvette", "2 door", 'A');
   Automobile  actressCar( "Chevrolet", 8, 2009, "silver",
						   "Angelina Jolie", "999-1234",
						   "Corvette", "convertible", 'A');
   Automobile  actorCar(   "Cadillac", 8, 2007, "black",
						   "Brad Pitt", "999-1234",
						   "Escalade", "4 door", 'A');
   Automobile	   cameramanTruck("Ford", 8, 2006, "white",
							  "John Doe", "000-1234",
							  "F-150", "2 door", 'M');

   garage.push_back(directorCar);

   garage.push_back(actressCar);

   garage.push_back(actorCar);

   cout << "Here is what is in the garage:\n";

   vector<int>::iterator p;

   for(p = garage.begin( ); p != garage.end( ); p++)
	  cout << *p << endl;

   cout << endl;

   Person  carBuyer(actorCar.getOwner( ));

   Automobile  newCar("Cadillac", 8, 2009, "silver",
					   "no owner", "000-0000",
					   "Escalade", "4 door", 'A');

   actorCar = newCar;
   actorCar.setOwner(carBuyer.getName( ), carBuyer.getPhone( ));

   cout << actorCar << endl;

   Person  truckBuyer(cameramanTruck.getOwner( ));

   Automobile	  newTruck("Ford", 8, 2009, "brown",
						 "no owner", "000-0000",
						 "F-150", "2 door", 'A');

   cameramanTruck = newTruck;
   cameramanTruck.setOwner(truckBuyer.getName( ), truckBuyer.getPhone( ));

   cout << cameramanTruck << endl;

   return 0;
}


everything works great except for this part of the code

for(p = garage.begin( ); p != garage.end( ); p++)


this is the error that gives me

no match for 'operator=' in 'p = (&garage)->std::vector<_Tp, _Alloc>::begin [with _Tp = Automobile, _Alloc = std::allocator<Automobile>]()'

and this one

no match for 'operator!=' in 'p != (&garage)->std::vector<_Tp, _Alloc>::end [with _Tp = Automobile, _Alloc = std::allocator<Automobile>]()'


can someone tell em please what is wrong???

Is This A Good Question/Topic? 0
  • +

Replies To: I'm getting an error for no match for operator

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3120
  • View blog
  • Posts: 19,163
  • Joined: 14-September 07

Re: I'm getting an error for no match for operator

Posted 22 April 2009 - 09:10 PM

An iterator has to match the vector type it will be traversing through. If you don't have it match it will not know how to iterate through it:

   vector<int>::iterator p;

//change to

   vector<Automobile>::iterator p;


Was This Post Helpful? 0
  • +
  • -

#3 isale8888  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 45
  • Joined: 29-October 08

Re: I'm getting an error for no match for operator

Posted 23 April 2009 - 08:45 PM

hey thank you!!
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,383
  • Joined: 10-May 07

Re: I'm getting an error for no match for operator

Posted 23 April 2009 - 08:52 PM

** Renamed title to be more descriptive of topic **
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1