Thanks for your response but I do not understand your comments (criticism). I mean no disrespect but I would like to understand your perspective. This is C++ code not
Java. Why not use the language features?
1) templates: Good for code reuse. Why make different graph classes graohInt, graphString, ... when the compiler is perfectly capable of generating similar code. Back to the dark days of the C programming language. Templates support generic programming. Think the Standard Template Library.
2) Why not nested classes? A graphNode is only part of a graph and has no business being made/accessed outside of the graph class. I made all the members public to simplify the access to the elements in this example. Real code would have private members and a public interface.
3) The graphNode contains one piece of data about the graph, so the graphNode is the template type, not the graph. A graph is simply a vector of graphNodes. I want to represent different graphs with different node values. For example, integer or
string node values, my data type node values, ...
4) Why not keep the interface to the class clean and easy to read/see its functionality. Many of the functions get rather long, addEdge, Kruskals algorithm, ...
The insertion operator must be implemented outside the class otherwise I would need to change the ostream class to include my data types. This is not possible unless I make a new derived type of the ostream class. What I am trying to do in the insertion operator is to call the classes member functions to display themselves. That is why the graph calls the insertion operator on the grapNode class. The graphNode knows about itself. I am trying to overload the global insertion operator so it acts like the primitive data types. Why should I need to treat my data types differently? For example, if val is an int I would write cout << val << endl; Why should I have to do something special (different) for my data types, like g.output(cout);
I am happy to learn something new, but what I am doing should be allowed by the language and yet it seems the compiler has an issue with it. How would you implement a general graph class?
Sincerely,
Tom