7 Replies - 11830 Views - Last Post: 05 May 2011 - 04:10 PM Rate Topic: -----

#1 sackdragon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-November 10

No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 02:45 PM

I have this project I'm doing but it won't let me push things into the deque. I have no idea why. Here is the code:
#include "Processor.h"
#include "Job.h"
#include <iostream>
#include <queue>

using namespace std;

Processor::Processor(int j){
	totalTime = 0;
	numberOfJobs = j;
	jobsCompleted = 0;
	jobsCreated = 0;
}

void Processor::process(){
	while(jobsCreated < numberOfJobs){
		Job * tempJob = new Job();
		tempJob->setTimeCreated(totalTime);
		tempJob->setTimeEnteredWaiting(totalTime);
		waitingQueue->push_front(tempJob);
		if(cpuQueue->size() < 10){
			cpuQueue->push_front(waitingQueue->front());
			tempJob->setTimeExitWaiting(totalTime);
			waitingQueue->pop_front();
		}
	}
	while(jobsCompleted < numberOfJobs){
		while(cpuQueue->size() < 10){
			cpuQueue->push_front(waitingQueue->front());
			waitingQueue->pop_front();
		}
		while(!cpuQueue->empty()){
			Job * tempJob = cpuQueue->front();
			cpuQueue->pop_front();
			cpuQueue->push_back(tempJob);
}
}



The project isn't done yet but it still shouldn't be giving this error. The exact error is:
Posted Image


Any help would be appreciated. Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: No Instance Of Overloaded Function "..." matches the argument

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2015
  • View blog
  • Posts: 5,409
  • Joined: 27-December 05

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 03:25 PM

Well, you don't show the declaration of cpuQueue in the code you posted, but it appears that you must have declared it as

deque<Job> *cpuQueue = new deque<Job>;

but you are trying to push tempJob which is a Job* into it. Change the queue to
deque<Job*> *cpuQueue = new deque<Job*>;

or change the push to
cpuQueue->push_front(*tempJob);

Was This Post Helpful? 1
  • +
  • -

#3 sackdragon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-November 10

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 03:39 PM

View Postr.stiltskin, on 05 May 2011 - 03:25 PM, said:

Well, you don't show the declaration of cpuQueue in the code you posted, but it appears that you must have declared it as

deque<Job> *cpuQueue = new deque<Job>;

but you are trying to push tempJob which is a Job* into it. Change the queue to
deque<Job*> *cpuQueue = new deque<Job*>;

or change the push to
cpuQueue->push_front(*tempJob);

Thanks! Changing to
cpuQueue->push_front(*tempJob);
worked!

Now I'm getting an error for this:
Job * tempJob = waitingQueue->front();


It's saying that "No suitable conversion function from "Job" to "Job *" exists. But when I try to change tempJob to a regular Job rather than a pointer, it still throws an error. Any ideas?

This post has been edited by sackdragon: 05 May 2011 - 03:40 PM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 03:48 PM

front() is not returning a pointer, it's returning a Job object.

You need to show more code, i.e., how the deque is declared, as well as providing the EXACT error message!

This post has been edited by JackOfAllTrades: 05 May 2011 - 03:49 PM

Was This Post Helpful? 0
  • +
  • -

#5 sackdragon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-November 10

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 03:53 PM

#ifndef PROCESSOR_H
#define PROCESSOR_H

#include <queue>
#include "Job.h"
#include <fstream>
#include <iostream>

using namespace std;

class Processor{
public:
	Processor(int);
	void process();
private:
	deque<Job> * cpuQueue;
	deque<Job> * waitingQueue;
	int numberOfJobs, jobsCompleted, jobsCreated; 
	double totalTime, idleTime;
	fstream myFile;
};

#endif


Here is the code for the .h file.
Was This Post Helpful? 0
  • +
  • -

#6 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2015
  • View blog
  • Posts: 5,409
  • Joined: 27-December 05

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 04:02 PM

The point is simply that you have to be consistent. If you make a queue of job pointers (Job*), then the things that you remove from the queue using e.g. front() are going to be Job*, so you have to assign them to a Job*.

On the other hand, if you make a queue of Job objects, then you are going to be removing Job objects, not pointers, so you will have to assign them to variables of type Job, not Job*.

So I can't really tell you which way to go -- you have to decide whether you want a queue of objects or pointers depending on what you are doing and how you want to implement it. Just pick one way or the other and stick to it.
Was This Post Helpful? 1
  • +
  • -

#7 sackdragon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 09-November 10

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 04:07 PM

Fixed everything! Thanks guys!
Was This Post Helpful? 0
  • +
  • -

#8 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2015
  • View blog
  • Posts: 5,409
  • Joined: 27-December 05

Re: No Instance Of Overloaded Function "..." matches the argument

Posted 05 May 2011 - 04:10 PM

Now I'm going to complicate your life even more. In your Processor class you declare
deque<Job> * cpuQueue;

and then presumably, maybe in the constructor, you have
cpuQueue = new deque<Job>;


Is there a reason why you are using dynamic allocation to create that queue (and same goes for the waitingQueue)? Does your Processor object create and discard and create new queues during the course of a run? Or does the same queue exist the entire time that the program is running?

In other words, is there a reason why you don't simply declare
dequeue<Job> cpuQueue;
and be done with it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1