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{
private:
Object **depends;
std::string ident;
int status;
int current;
int ndepends;
public:
Object(std::string id){
status=0;
ident=id;
depends=NULL;
ndepends=0;
current=0;
}
~Object() { delete depends; }
void setdepends(int n){
ndepends=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";
exit(0);
}
status=1;
for (int i=0; i < ndepends; i++) depends[i]->topo();
cout << ident << " ";
status=2;
}
void Show(){
cout << ident << " : ";
for( int i=0; i < ndepends; i++) cout << depends[i]->ident
<< " ";
cout << "\n";
}
};
class Graph{
Object **graph;
int nobjects;
public:
Graph(){ nobjects=0; graph=NULL; }
~Graph(){
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;
nobjects=0;
fin >> buffer;
while(buffer != "-"){
nobjects++;
fin>>buffer;
}
fin.seekg(0,ios::beg);
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.seekg(0,ios::beg);
graph[i]->setdepends(ndepends);
}
fin >> buffer;
while(buffer != "-"){
graph[i]->setdepend(graph[atoi(buffer.c_str())]);
fin>>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();
graph->show();
graph->topo();
graph->read(argv[1]);
}