I am writing a sort program and i am getting the error " error: no matching function for call to 'Object::setdepend(Object*&)' " in this line " graph->setdepend(graph[atoi(buffer.c_str())]); " which is in my read function. I am not sure how to fix this, can anyone help?

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;

class Object{
	Object **depends;
	std::string ident;
	int status;
	int current;
	int ndepends;

	Object(std::string id){

	~Object() { delete depends; }

	void setdepends(int n){
		depends = new Object*[n];

	void setdepend(Object **graph, int idx){
		if (current >= ndepends) return;
		depends[current++] = graph[idx];

	void topo(){
		if (status==2) return;
		if (status==1){
			cout << "uh oh\n";
		for (int i=0; i < ndepends; i++) depends[i]->topo();
		cout << ident << " ";
	void Show(){
		cout << ident << " : ";
		for( int i=0; i < ndepends; i++) cout << depends[i]->ident
			<< " ";
		cout << "\n";
class Graph{
	Object **graph;
	int nobjects;

	Graph(){ nobjects=0; graph=NULL; }

		for(int i=0; i<nobjects; i++) delete graph[i];
		delete graph;

	void read(char *filename){
		fstream fin;
		fin.open(filename, ios::in);
		std::string buffer;
		fin >> buffer;
		while(buffer != "-"){

		graph = new Object*[nobjects];
		fin >> buffer;
		int i=0;
		while (buffer != "-"){
			graph[i++] = new Object(buffer.c_str());
		for (int i=0; i<nobjects; i++){
			long mark = fin.tellg();
			int ndepends=0;
		fin >> buffer;
		while(buffer != "-"){
	void show() { 
		for (int i=0; i < nobjects; i++ ) graph[i]->Show();

	void topo() {
		for (int i=0; i < nobjects; i++ ) graph[i]->topo();


int main(int argc, char **argv)
	if (argc != 2) {  
      cout << "\nUsage: " << argv[0] << " <filename>\n";
      exit (0);
	Graph *graph = new Graph();

Well, I'm not sure about how all the stuff you have crammed into that line works, but I do know that you are trying to call setdepend() with only 1 argument and it requires 2. What did you forget to send to it?

wait... nvm.... You have 2 functions with confusingly similar names, I was looking at the wrong one...

hmmm...... No, I was looking at the correct one. You are calling setdepend(), but your call is set up more like a call to setdepends().
Do you see what I mean about the confusingly similar names?

Edited 6 Years Ago by Fbody: n/a

Yes well i could change the names i suppose. However this line " graph->setdepend(graph[atoi(buffer.c_str())]); " was given to me by my professor, so i didnt forget anything in it.

Just because he gave it to you, doesn't mean it's correct. I can't begin to tell you about all the compile errors I had to fix in instructor-issued files this past semester. There was always something that had to be fixed before it would work.

All that it being instructor-issued means is that either your professor forgot something, or your implementation of the Object::setdepend() method is incorrect.

Either way, the call does not match the definition and something has to change. You need to either:
1. add a default value to the idx parameter (probably not a good choice for this situation)
2. eliminate the idx parameter
3. correct the format of your call

I suggest you take a closer look at the writeup for your assignment to see what the proper requirements are.

Edited 6 Years Ago by Fbody: n/a

This article has been dead for over six months. Start a new discussion instead.