Answer the question
In order to leave comments, you need to log in
Default parameters in a friend function. Why is he cursing?
I am writing a "graph" class and a "breadth-first search" friend function. In the function, in the "your graph" parameter, I pass a default constructor that creates a graph from 1 vertex. The following code will tell for me:
/**********
* граф содержит:
* количество точек
* вектор связности
**********/
class Graph {
int vs;
std::vector<int> **relations;
public:
Graph(int _vs = 1){
vs = _vs;
relations = new std::vector<int>*[_vs];
for(int i = 0; i < _vs; i++) relations[i] = new std::vector<int>;
}
Graph &bind(int from, int to);
// печать в стандартный поток
friend std::ostream & operator <<(std::ostream &out, Graph &g);
// поиск в ширину
friend int **bfs(Graph g = Graph::Graph());
};
Answer the question
In order to leave comments, you need to log in
why does the compiler swear at my default parameter?
I would venture to suggest that he wants to see just Graph() instead of Graph::Graph(). And a little offtopic, I may not understand something, but why the graph is passed as a default parameter to the width traversal, it's a little strange to bypass the width of the default graph (I assume an empty graph).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question