-5

Hey guys i am working on a program that will simulate a queue at a call center but im running into this problem and have no idea why...

Error: Binary '==' : no operator found which takes a left-hand operand of type 'agent' (or there is no acceptable conversion)

#include "stdafx.h"
#include "dialer.h"


dialer::dialer()
{
    //hidden
}

dialer::dialer(campaign *campaignOnDialer)
{
    this->campaignOnDialer = campaignOnDialer;
}

void dialer::tick()
{


    for(int callCount = 0; callCount <= callsOnDialer.size() -1; callCount++)
    {
        //Goes through each call in queue and ticks
        callsOnDialer.front().tick();   
        callsOnDialer.push(callsOnDialer.front());
        callsOnDialer.pop();
    }
}

void dialer::addAgent(agent newAgent)
{
    agentsOnDialer.push_back(newAgent);
}

agent* dialer::searchAgentById(int id)
{
    std::list<agent>::iterator frontIterator = agentsOnDialer.begin();
    agent foundAgent;

    while(frontIterator->getAgentId() != agentsOnDialer.end()->getAgentId())
    {
        if(frontIterator->getAgentId() == id)
        {
            foundAgent = frontIterator->getInstance();
            return &foundAgent;
        }

        else
            frontIterator++;
    }
    return NULL;
}

bool dialer::removeAgent(int id)
{
    agent* removeAgent = searchAgentById(id);   

    if(removeAgent == NULL)
        return false;

    agentsOnDialer.remove(*removeAgent);
    return true;
}

void dialer::assignNextCall()
{
    int assignedAgentId = getIdleAgentId();

    if(assignedAgentId == -1 || callsOnDialer.empty())
        return;

    int nextCallId = callsOnDialer.front().getCallId();

}

int dialer::getIdleAgentId()
{

}
MathMajor
  • 269
  • 1
  • 2
  • 13
  • 1
    You have [undefined behaviour](http://stackoverflow.com/questions/6441218/can-a-local-variables-memory-be-accessed-outside-its-scope). – chris Aug 14 '13 at 21:55
  • 1
    Can you show me where `==` is applied to an `agent` in the code? – Miserable Variable Aug 14 '13 at 21:56
  • The functions that arn't defined are not being used at all... its the function i just created that gave me the problem – MathMajor Aug 14 '13 at 21:56
  • I dont know - thats why i am so stumped, i havnt used the == operator anywhere in this code, why am i getting this error? – MathMajor Aug 14 '13 at 21:57
  • What ***line*** is the error on? (Errors occur on specific lines of code!) – abelenky Aug 14 '13 at 21:57
  • @chris No, the code cannot be executed since there's a compile-time error, and there's no compile-time undefined behaviour here. –  Aug 14 '13 at 21:57
  • 1
    `return &foundAgent;` - returning the address of a local variable is undefined behaviour. Your compiler should've told you that. – Daniel Kamil Kozar Aug 14 '13 at 21:57
  • @hvd, Sorry, let me rephrase that as "You will have undefined behaviour when you get your program to run." It's still important to know about. – chris Aug 14 '13 at 22:00
  • @chris Sure, no argument there. :) –  Aug 14 '13 at 22:01
  • How can you place "i havnt used the == operator anywhere in this code" against `if(frontIterator->getAgentId() == id)`??? – Maarten Bodewes Aug 14 '13 at 22:02
  • 1
    You can't dereference an `end()` iterator. This makes no sense: `agentsOnDialer.end()->getAgentId()`. – Blastfurnace Aug 14 '13 at 22:09

1 Answers1

4

The problem seems to be that the method getAgentId() in your agent class does not return an int; rather it returns an agent. Besides that everything seems to be able to work.

Also, there's a minor discrepancy in your removeAgent(int id) function. Try renaming the agent* removeAgent to agent* agentToRemove. Even though this technically shouldn't be a problem it's not the best practice to name a local variable the same as a function.

Forest Kunecke
  • 2,160
  • 15
  • 32
  • Here is the function... I dont believe that its the issue though int agent::getAgentId() const { return agentId; } – MathMajor Aug 14 '13 at 22:00