I have created a class called data and overloaded some operators to perform some operation on the object of this class.
class data{
public:
int distance;
int parent;
int node_number;
data();
data(int, int, int);
bool operator<(data &);
bool operator>(data &);
bool operator>=(data &);
bool operator<=(data &);
bool operator==(data &);
void operator=(data &);
data operator+(int &);
};
two of the overloaded operator definition is as follows.
For assignment operator:
void data::operator=(data & d){
this->distance = d.distance;
this->parent = d.parent;
this->node_number = d.node_number;
}
for addition operator:
data data::operator+(int & d){
data l;
l.node_number = this->node_number;
l.parent = this->parent;
l.distance = this->distance + d;
return l;
}
When I am using object of this class in my one of the function like this..
void d1::dijkstra::relax(int u, int v){
data accumulated_weight;
accumulated_weight = *this->v[u] + this->g[u][v]; //Getting error at this line
if(*this->v[v] > accumulated_weight){
this->fh.fib_heap_decrease_key(*this->v[v], accumulated_weight);
this->v[v]->parent = u;
}
}
I am getting error at the line indicated.
Error says: no match for ‘operator=’ (operand types are ‘data’ and ‘data’)| note: no known conversion for argument 1 from ‘data’ to ‘data&’
What is wrong in the method I am using? What should be proper way to use this?
Edit: This pointer is referring to this class:
namespace d1{
class dijkstra{
private: int number_of_vertices;
private: std::vector< std::vector<int> > g;
private: std::vector<data *> v;
private: int source;
private: a1::heap fh;
private: void initialize_single_source();
private: void relax(int, int);
public: dijkstra(std::vector< std::vector<int> > &, int);
public: void run();
public: void print_graph();
};
};