Pointing to a Queue of Pointers?

This is a discussion on Pointing to a Queue of Pointers? within the C++ Programming forums, part of the General Programming Boards category; I'm trying to have a pointer point to teh first object in a Queue of Objects so I can move ...

  1. #1
    Slime Dragoon_42's Avatar
    Join Date
    Feb 2003
    Location
    Vancouver
    Posts
    90

    Unhappy Pointing to a Queue of Pointers?

    I'm trying to have a pointer point to teh first object in a Queue of Objects so I can move it to a Map but I'm getting odd errors. Car and Date are classes I've created, but Date has nothing to do with Car assignments so I don't understand the error codes.

    Date.h
    Code:
    #include"date.h"
    typedef enum {NA, available, service, rented, junked} status;
    class Car
    {
    	private:
    	string plate;
    	status stat;
    	int mileage;
    	int lastServiceMileage;
    	Date outDate;/*date rented*/
    	Date inDate;/*date due back*/
    	
    	public:
    	Car(string lic="", unsigned miles=0)
    	{
    		plate=lic;
    		mileage=miles;
    		stat=NA;
    	}
    	
    	string getPlate()
    	{
    		return plate;
    	}
    	
    	int getMile()
    	{
    		return mileage;
    	}
    	
    	bool operator==(const Car &car2)
    	{
    		return(plate==car2.plate);
    	}
    	
    	bool operator<(const Car &car2)const
    	{
    		return(plate<car2.plate);
    	}
    	
    	int mileageCompareTo(const Car &car2)const
    	{
    		return(mileage-car2.mileage);
    	}
    	
    	string convertStatus()const
    	{
    		/*NA, available, service, rented, junked*/
    		switch(stat)
    		{
    			case NA: return "NA";
    				break;
    			case available: return "available";
    				break;
    			case service: return "service";
    				break;
    			case rented: return "rented";
    				break;
    			case junked: return "junked";
    				break;
    			default: return "NA";
    				break;
    		}
    	}
    	
    	void chStat(string sta)
    	{
    		if(sta=="NA") stat=NA;
    		if(sta=="available") stat=available;
    		if(sta=="service") stat=service;
    		if(sta=="rented") stat=rented;
    		if(sta=="junked") stat=junked;
    	}
    };
    Car.h
    Code:
    #if !defined Date_h
    #define Date_h
    #include <iostream>
    #include <string>
    using std::string;
    using std::cout;
    using std::cin;
    using std::ostream;
    using std::istream;
    class DateException{
    //Note really should write display member function and insertion operator helper function
    public:
    	string message;
    	DateException(const string & msg = ""){message = msg;}
    };
    
    class Date { //does note need copy constructor or assignment operator WHY?
       public :
          Date(int month = 1, int day =1, int year = 2001);
          void setDate(int month = 1, int day =1, int year = 2000) throw (DateException);
          void setDay(int day)throw (DateException);
          void setMonth(int month)throw (DateException);
          void setYear(int year)throw (DateException);
    	  Date operator ++(int) ;              //Notice new operation
          int day()const {return _day;}
          int year()const {return _year; }
          int month()const {return _month; }
          void display(ostream & out = cout)const; //  month/day/year format no \n
          void input(istream & in = cin); //   month/day/year format
          bool operator == ( const Date & d2)const;
          bool operator < ( const Date & d2)const ;
    	  bool operator > (const Date & d2) const ;
       protected:
          int _month;
          int _day;
          int _year;
     } ;
    
    //helper functions
    
    bool operator != (const Date & d1, const Date & d2) ;
    
    ostream & operator << (ostream & out, const Date & d1) ;
    
    istream & operator >> (istream & in,  Date & d1) ;
    // tests if year is a leap year
    bool leapYearTest(int year) ;
    // a crutial piece of information -- the number of days in a month
    // returns int value
    int maxNumDaysinMonth(int the_month, int the_year);
    
    //compute the difference in days between two dates
    //Be sure to check which is smaller -- d1 or d2
       int difference(const Date &d1, const Date &d2);
    
    // checks if a date is a valid one.
       bool isValid (Date d);
    #endif // !defined Date_h
    Main.cpp
    Code:
    #include"car.h"
    #include<map>   /**/
    #include<queue> /*cars being serviced*/
    
    void list();
    
    int main()
    {
    	string command;
    	int day,month,year,mileage;
    	string lic;
    	//Date current;
    	std::map<string,Car*> ourCars;
    	std::multimap<string,Car*> available4Rent;
    	std::queue<Car*> toBeServiced;
    	Car * ca;
    	while(command!="quit")
    	{
    		list();
    		cout<<"Please enter command: ";
    		cin>>command;
    		
    		if(command=="setdate")
    		{
    			cin>>day>>month>>year;
    			//current.setDate(month, day, year);
    		}
    		if(command=="new")
    		{
    			cin>>lic>>mileage;
    			ca=new Car(lic,mileage);
    			ourCars.insert(std::pair<string,Car*>(lic,ca));
    			(*ca).chStat("service");
    			toBeServiced.push(ca);
    		}
    		if(command=="serviced")
    		{
    			ca=toBeServiced.front();
    			(*ca).chStat("available");
    			available4Rent.insert(std::pair<string,Car*>((*ca).getPlate(), ca));
    			toBeServiced.pop();
    		}
    		
    	}
    	return 0;
    }
    
    void list()
    {
    	cout<<"setdate mm dd yyyy \n";
    	cout<<"new 'license plate' 'mileage' \n";
    	cout<<"serviced \n";
    	cout<<"list\n";
    	cout<<"available\n";
    	cout<<"rent mm/dd/yy\n";
    	cout<<"return 'license plate' 'current mileage'\n";
    	cout<<"rented\n";
    	cout<<"due\n";
    	cout<<"when 'license plate'\n";
    	cout<<"overdue\n";
    	cout<<"rentcar 'license plate' 'date of return'\n";
    	cout<<"junk 'license plate'\n";
    	cout<<"listjunked\n";
    	cout<<"summary 'license plate'\n";
    	cout<<"quit\n";
    }

    Errors:
    H:\Program>gpp -Wall rent.cpp
    c:/djgpp/tmp/ccDXn05B.o(.text+0xcc):rent.cpp: undefined reference to `Date:ate
    [in-charge](int, int, int)'
    c:/djgpp/tmp/ccDXn05B.o(.text+0x24e):rent.cpp: undefined reference to `Date::set
    Date(int, int, int)'
    c:/djgpp/tmp/ccDXn05B.o(.gnu.linkonce.t._ZN3CarC1ESsj+0x26):ren t.cpp: undefined
    reference to `Date:ate[in-charge](int, int, int)'
    c:/djgpp/tmp/ccDXn05B.o(.gnu.linkonce.t._ZN3CarC1ESsj+0x3e):ren t.cpp: undefined
    reference to `Date:ate[in-charge](int, int, int)'
    collect2: ld returned 1 exit status
    Last edited by Dragoon_42; 04-08-2004 at 10:16 PM. Reason: My problem isn't waht I thought it was...

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Your errors suggest a problem with the Date class, not with your queue of pointers to Car. Are you sure that you gave the Date::Date and Date::set member functions bodies?
    My best code is written with the delete key.

  3. #3
    Slime Dragoon_42's Avatar
    Join Date
    Feb 2003
    Location
    Vancouver
    Posts
    90
    Yes, they have bodies. I figured it out, my exception handling was causing errors. Thanks for the help and direction to my faulty Date class!
    Last edited by Dragoon_42; 04-08-2004 at 10:26 PM. Reason: Figured it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 05:23 AM
  2. Queue implementation
    By kolliash in forum C Programming
    Replies: 1
    Last Post: 06-01-2008, 09:25 AM
  3. Priority Queue Help
    By cjwenigma in forum C++ Programming
    Replies: 6
    Last Post: 11-15-2007, 12:48 AM
  4. ADT queue
    By ^xor in forum C Programming
    Replies: 4
    Last Post: 06-15-2005, 06:43 AM
  5. Data structs and pointers
    By vegaaces in forum C Programming
    Replies: 2
    Last Post: 04-30-2005, 01:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21