having problems using the given .h and .template files for my lab... here is what errors i get:
seems it doesn't like the definition of MAXIMUM for some reason. here is the graph.h file where MAXIMUM is declared:Code:Compiling... lab_5.cpp c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.h(78) : error C2258: illegal pure syntax, must be '= 0' c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.h(95) : see reference to class template instantiation 'main_savitch_15::graph<Item>' being compiled c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.h(78) : error C2252: 'MAXIMUM' : pure specifier can only be specified for functions c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.h(95) : see reference to class template instantiation 'main_savitch_15::graph<Item>' being compiled c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.h(92) : error C2065: 'MAXIMUM' : undeclared identifier c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.h(95) : see reference to class template instantiation 'main_savitch_15::graph<Item>' being compiled c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.template(18) : error C2039: 'MAXIMUM' : is not a member of 'graph<Item>' c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.template(18) : error C2734: 'MAXIMUM' : const object must be initialized if not extern c:\documents and settings\all users\documents\school\nonlinear data structures\lab_5\graph.template(18) : error C2734: 'MAXIMUM' : const object must be initialized if not extern Error executing cl.exe. lab_5.exe - 6 error(s), 0 warning(s)
we changed it to const int from static const int because the teacher said that VC++ before .NET had trouble with that or something... i tried changing it to static const int but got the same errors.Code:#ifndef MAIN_SAVITCH_GRAPH_H #define MAIN_SAVITCH_GRAPH_H #include <cstdlib> // Provides size_t #include <set> // Provides set namespace main_savitch_15 { template <class Item> class graph { public: // MEMBER CONSTANTS const int MAXIMUM = 50; // CONSTRUCTOR graph( ) { many_vertices = 0; } // MODIFICATION MEMBER FUNCTIONS void add_vertex(const Item& label); void add_edge(int source, int target, int weight); void remove_edge(int source, int target); Item& operator [ ] (int vertex); // CONSTANT MEMBER FUNCTIONS int size( ) const { return many_vertices; } int is_edge(int source, int target) const; std::set<int> neighbors(int vertex) const; Item operator[ ] (int vertex) const; private: int edges[MAXIMUM][MAXIMUM]; Item labels[MAXIMUM]; int many_vertices; }; } #include "graph.template" // Include the implementation. #endif
here is the graph.template file if you want to check that out too:
Code:#include <cassert> // Provides assert #include <set> // Provides set namespace main_savitch_15 { template <class Item> const int graph<Item>::MAXIMUM; template <class Item> void graph<Item>::add_edge(int source, int target, int weight) // Library facilities used: cassert, cstdlib { assert(source < size( )); assert(target < size( )); edges[source][target] = weight; } template <class Item> void graph<Item>::add_vertex(const Item& label) // Library facilities used: cassert, cstdlib { int new_vertex_number; int other_number; assert(size( ) < MAXIMUM); new_vertex_number = many_vertices; many_vertices++; for (other_number = 0; other_number < many_vertices; ++other_number) { edges[other_number][new_vertex_number] = 32768; edges[new_vertex_number][other_number] = 32768; } labels[new_vertex_number] = label; } template <class Item> int graph<Item>::is_edge(int source, int target) const // Library facilities used: cassert, cstdlib { assert(source < size( )); assert(target < size( )); return edges[source][target]; //return "weight" } template <class Item> Item& graph<Item>::operator[ ] (int vertex) // Library facilities used: cassert, cstdlib { assert(vertex < size( )); return labels[vertex]; // Returns a reference to the label } template <class Item> Item graph<Item>::operator[ ] (int vertex) const // Library facilities used: cassert, cstdlib { assert(vertex < size( )); return labels[vertex]; // Returns only a copy of the label } template <class Item> std::set<int> graph<Item>::neighbors(int vertex) const // Library facilities used: cassert, cstdlib, set { std::set<int> answer; int i; assert(vertex < size( )); for (i = 0; i < size( ); ++i) { if (edges[vertex][i]) answer.insert(i); } return answer; } template <class Item> void graph<Item>::remove_edge(int source, int target) // Library facilities used: cassert, cstdlib { assert(source < size( )); assert(target < size( )); edges[source][target] = 32768; } }
any suggestions would be appreciated...
[edit]sorry bout the long lines in the error code![/edit]



LinkBack URL
About LinkBacks


