Thread: Is there anything illogical here...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Is there anything illogical here...

    Code:
    void Rental::ViewContract()
    {
    	system("cls");
    
    	ContractsIterator iter = find();
    	
    	/* 
    	 * Load contract list with contracts saved in file
    	 *
    	 */
    	
    	Contract contract;
    	ifstream infile;
    	char filename[MAX_PATH] = "contract.txt";
    	
    	infile.open(filename);
    	while ( !contract.Read(infile, false, "0") ) {
    		contractList.push_back(contract);	
    	}
    
    	/* 
    	 * View Contract on screen 
    	 *
    	 */
    
    	system("cls");
    	
    	// Headings ....
    
    	printf("\n\n%-18s%-16s%-8s%-12s%-15s\n\n",	"Ref. No", 
    		"Rental-Type", "Group", "Car-Reg", "Date-Time of Contract");	
    
    	if(iter != contractList.end() )  //  < -- CXX0039: Error: symbol is ambiguous
    
    	{
                  // Displaying the Contract  ... 
    	}
    	else {
    		puts("\n\nNo contracts !");
    	}
    }
    RUN-TIME Error! complains about contractList.end()

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Oops! missplaced this ContractsIterator iter = find();, should be after i read from file..

    But still, why is it crashing.. Whether or not i've loaded from file, .end() should always exists

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Are you using your own Read() member function correctly? Can you please post your whole class.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Wait. Are you getting a compile-time error or a run-time error? (Error: symbol is ambiguous sounds like a compile-time error to me, but what do I know.) How many things do you have called contractList?

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    610
    Quote Originally Posted by tabstop View Post
    Wait. Are you getting a compile-time error or a run-time error? (Error: symbol is ambiguous sounds like a compile-time error to me, but what do I know.) How many things do you have called contractList?
    the "Error: symbol is ambiguous" is on the watch window when i debug, i dragged ConractList to the watch window, as i reach the while loop, i get the debug/run-time error .. Well, as i said, after replacing the find() function it now works... But then my thinking you should be able to point to the end of the list whether or not you've loaded stuff to the Vector!! besides, read loads stuff before i call .end() ...

    Code:
    // Read the contract details from file, or enter new contract
    bool Contract::Read(std::istream& indata, bool newContract, std::string refNum)
    {
    	indata >> *this;	
    
    	// Set rental dates to current date
    	if(newContract)	
    	{
    		contractID=refNum;
    		issued.SetDate( issued.getCurrentTime() );
    	}
    	else
    		indata >> issued;
    
    	return indata.fail();
    }
    
    // Overload for reading contract details from a filestream
    std::istream& operator>>(std::istream& in, Contract& contract)
    {
    	std::string contractID;
    	std::string rentalType;
    	std::string carReg;
    	char carGrp;
    
    	in >> contractID;
    	in >> rentalType;
    	in >> carGrp;
    	in >> carReg;
    
    	contract.SetContractDetails(carReg, rentalType, carGrp, contractID);
    
    	return in;
    }

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Code:
    if ( iter != contractList.end() )
    Is iter an iterator of the contractList container or of a different container?
    What does the find() function look like?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by csonx_p View Post
    the "Error: symbol is ambiguous" is on the watch window when i debug, i dragged ConractList to the watch window, as i reach the while loop, i get the debug/run-time error .. Well, as i said, after replacing the find() function it now works... But then my thinking you should be able to point to the end of the list whether or not you've loaded stuff to the Vector!! besides, read loads stuff before i call .end() ...
    My guess is that error it is simply a problem with how you tell the debugger to give you the intermediate result: that you are using an ambitious watch expression. That would not cause a crash; if there is a crash the problem has nothing to do with that message.

    You can probably fix the message by qualifying contractList in your watch expression, such as by using this->contractList.end(). You do not need to do this to the source.
    Last edited by King Mir; 09-09-2008 at 07:20 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM