code_junkie

C++ compiler unable to find function (namespace related)

Nov 13th, 2011
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. (MAIN-NAMESPACE){
  2.  
  3. a bunch of functions/classes I need to implement...
  4.  
  5. (EXCEPTIONS-NAMESPACE){
  6.  
  7. a bunch of exceptions
  8. }
  9.  
  10. (POINTER-COLLECTIONS-NAMESPACE){
  11.  
  12. Set and LinkedList classes, plus iterators
  13. }
  14. }
  15.  
  16. template<typename T>
  17. std::ostream& operator<<(std::ostream& os,
  18. const MAIN-NAMESPACE::POINTER-COLLECTIONS-NAMESPACE::Set<T>& set)
  19.  
  20. Set A
  21. Set B
  22. Set C
  23. double num
  24.  
  25. namespace A
  26. {
  27. namespace B
  28. {
  29. class C{};
  30. }
  31.  
  32. }
  33.  
  34. void f(A::B::C*);
  35.  
  36. namespace A
  37. {
  38. void f(int*); // try commenting
  39. using ::f; // these two lines
  40. void g()
  41. {
  42. B::C* c;
  43. f(c);
  44. }
  45. }
  46.  
  47. ::operator<<( cout, myObj );
  48.  
  49. namespace MTM {//This is the MAIN-NAMESPACE
  50.  
  51. namespace PointerCollections {
  52.  
  53. (ITERATORS AND PREDICATE CLASSES)
  54.  
  55. template<typename T>
  56. class Set {
  57. public:
  58.  
  59. /////////////////////////////////
  60. // Definitions
  61. /////////////////////////////////
  62.  
  63. private:
  64.  
  65. /////////////////////////////////
  66. // Definitions
  67. /////////////////////////////////
  68.  
  69. };
  70.  
  71.  
  72. ///////////////////////////////////////////////////////////////////////////////
  73. // The implementation part.
  74. ///////////////////////////////////////////////////////////////////////////////
  75. }
  76. }
  77. // operator<< - the same a Set::print(std::ostream& os,
  78. // const BinaryPredicate<T>& predicate)
  79. // function called with the 'predicate' parameter omitted
  80. template<typename T>
  81. std::ostream& operator<<(std::ostream& os,
  82. const MTM::PointerCollections::Set<T>& set){
  83.  
  84. set.print(os);
  85. return os;
  86. }
  87.  
  88. namespace MTM {
  89. using std::ostream;
  90.  
  91. class Schedule {
  92. public:
  93. ///////////////////
  94. //Definitions, including:
  95. ///////////////////
  96. void registerStation(string stationName);
  97. void reportRegisteredStations(std::ostream& outputStream) const;
  98.  
  99. private: //My database
  100. //All the classes Set recieves are defined elsewhere
  101. Set<RegisteredStation> places;
  102. Set<BusLine> busses;
  103. Set<TrainLine> trains;
  104. double tarifForBuses;
  105. double tarifForTrains;
  106. };
  107.  
  108. }
  109.  
  110. Schedule s();
  111. s.registerStation("1");
  112. s.reportRegisteredStations(cout);//This invokes the error. Definition follows:
  113.  
  114. void Schedule::reportRegisteredStations(std::ostream& outputStream) const{
  115.  
  116. outputStream<<places;
  117. }
  118.  
  119. #include <iostream>
  120. #include <string>
  121. using std::string;
  122.  
  123. namespace MTM {//This is the MAIN-NAMESPACE
  124.  
  125. namespace PointerCollections {
  126.  
  127. template<typename T>
  128. class Set {
  129. };
  130.  
  131.  
  132. }
  133. }
  134. template<typename T>
  135. std::ostream& operator<<(std::ostream& os,
  136. const MTM::PointerCollections::Set<T>& set){
  137.  
  138. return os;
  139. }
  140.  
  141. namespace MTM {
  142. using std::ostream;
  143. using PointerCollections::Set;
  144. class Schedule {
  145. public:
  146. ///////////////////
  147. //Definitions, including:
  148. ///////////////////
  149. void registerStation(string stationName);
  150. void reportRegisteredStations(std::ostream& outputStream) const;
  151.  
  152. private: //My database
  153. //All the classes Set recieves are defined elsewhere
  154. Set<int> places;
  155. Set<int> busses;
  156. Set<int> trains;
  157. double tarifForBuses;
  158. double tarifForTrains;
  159. };
  160. void Schedule::reportRegisteredStations(std::ostream& outputStream) const{
  161.  
  162. outputStream<<places;
  163. }
  164.  
  165. }
  166.  
  167. int main()
  168. {
  169. MTM::Schedule s;
  170. s.reportRegisteredStations(std::cout);
  171. }
  172.  
  173. namespace test {
  174. class A {};
  175. }
  176.  
  177. namespace test {
  178. std::ostream& operator<<( std::ostream&, A const & );
  179. }
  180.  
  181. namespace test2 {
  182. void g() {
  183. namespace1::class1 c1;
  184. namespace2::namespace3::class2 c2;
  185. f( c1, c2 );
  186. }
  187. }
Add Comment
Please, Sign In to add comment