Problem

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Hi, I'm back :P.
      I'm programming a MUD game with the book "MUD game programming by Ron Penton" and i have had some issues that i can't get the solution.
      Here, This is the entityDataBase class(the code is in spanish :) but can be understand it)
      There are some problems like these:
      27 expected `)' before '&' token
      In member function `database& Tyrim::EntityBaseDatos<database>::iterator::operator*()':
      35 `itr' undeclared (first use this function)
      I can't understand it. I work with Dev C++, and the problem is in "typedef map<entityid, database> contenedor;"


      C Source Code

      1. #ifndef ENTITYBASEDATOS_H
      2. #define ENTITYBASEDATOS_H
      3. #include <string>
      4. #include <map>
      5. #include <vector>
      6. #include <fstream>
      7. #include <iterator>
      8. #include "Entity.h"
      9. using std::istream;
      10. using std::ostream;
      11. namespace Tyrim{
      12. template<class database>
      13. class EntityBaseDatos{
      14. public:
      15. typedef map<entityid, database> contenedor;
      16. //clase que hereda de iterator
      17. class iterator : public contenedor::iterator{
      18. public:
      19. iterator(){}//constructor por defecto
      20. iterator(contenedor::iterator& p_itr){ //constructor copia
      21. contenedor::iterator& itr = *this;
      22. itr = p_itr;
      23. }
      24. //desreferencia el iterador para devolver la referencia a la que apunta
      25. inline database& operator*(){
      26. contenedor::iterator& itr = *this;
      27. return itr->second;
      28. }
      29. inline database* operator->(){
      30. contenedor::iterator& itr = *this;
      31. return &(itr->second);
      32. }
      33. };//end class iterator
      34. inline static iterator begin(){
      35. return iterator(m_map.begin());
      36. }
      37. inline static iterator end(){
      38. return iterator(m_map.end());
      39. }
      40. inline static iterator find(entityid p_id){
      41. return iterator(m_map.find(p_id));
      42. }
      43. static iterator findfull(const string& p_str){
      44. return std::find_if(begin(),end(),BusquedaEntDeEntity(p_str));
      45. }
      46. static iterator find(const string& p_str){
      47. return double_find_if(begin(),end(),BusquedaEntDeEntity(p_str),BusquedaParcDeEntity(p_str));
      48. }
      49. inline static database& get(entityid p_id){
      50. iterator itr = find(p_id);
      51. if(itr == 0)
      52. throw std::exception();
      53. return *itr;
      54. }
      55. inline static bool has(entityid p_id){
      56. return (m_map.find(p_id) != m_map.end());
      57. }
      58. inline static bool hasfull(const string& p_str){
      59. return findfull(p_str) != end();
      60. }
      61. inline static bool has(const string& p_str){
      62. return find(p_str) != end();
      63. }
      64. inline static int size(){return (int)m_map.size();}
      65. static entityid EncontrarDisponibleID(){
      66. if(m_map.size() == 0)
      67. return 1;
      68. if(m_map.size() == m_map.rend()->first)
      69. return m_map.size() + 1;
      70. entityid dispid = 0;
      71. entityid previo = 0;
      72. map<entityid,database>::iterator itr = m_map.begin();
      73. while(!dispid){
      74. if(itr->firts != previo + 1)
      75. dispid = previo + 1;
      76. else
      77. previo = itr->first;
      78. itr++;
      79. }
      80. return dispid;
      81. }
      82. protected:
      83. static map<entityid, database> m_map;
      84. }; //end class EntityBaseDatos
      85. //class o typename lo mismo es
      86. template<typename database>
      87. class EntityBaseDatosVector{
      88. typedef std::vector<database>::iterator iterator;
      89. public:
      90. inline static iterator begin(){return m_vector.begin() + 1;}
      91. inline static iterator end(){return m_vector.end();}
      92. inline static size_t size(){return m_vector.size() - 1;}
      93. inline static database& get(entityid p_id){
      94. if(p_id >= m_vector.size() || p_id == 0)
      95. throw std::exception();
      96. return m_vector[p_id];
      97. }
      98. protected:
      99. static std::vector<database> m_vector;
      100. };
      101. }//end Tyrim
      102. #endif
      Display All


      //class Entity

      C Source Code

      1. #ifndef ENTITY_H
      2. #define ENTITY_H
      3. #include <string>
      4. #include "Librerias/BasicLib.h"
      5. using namespace std;
      6. namespace Tyrim{
      7. typedef unsigned int entityid;
      8. class Entity{
      9. public:
      10. //constructor
      11. inline Entity(){
      12. m_id = 0;
      13. m_name = "UNDEFINED";
      14. }
      15. inline string& Nombre(){return m_name;}
      16. inline entityid& id(){return m_id;}
      17. inline string NomMin(){
      18. return BasicLib::LowerCase(m_name);
      19. }
      20. inline bool BuscarEnt(const string& p_str){
      21. return NomMin() == BasicLib::LowerCase(p_str);
      22. }
      23. inline bool BuscarParcial(const string& p_str){
      24. if(p_str.size() == 0)
      25. return true;
      26. string nombre = NomMin();
      27. string busqueda = BasicLib::LowerCase(p_str);
      28. size_t pos = nombre.find(busqueda);
      29. while(pos != string::npos){
      30. if(pos == 0 || m_name[pos -1] == ' '){
      31. return true;
      32. }
      33. pos = nombre.find(busqueda, pos +1);
      34. }
      35. return false;
      36. }
      37. protected:
      38. entityid m_id;
      39. string m_name;
      40. };
      41. struct BusquedaEntDeEntity{
      42. BusquedaEntDeEntity(const string& p_str)
      43. :m_name(p_str){/*No hace nada*/};
      44. bool operator()(Entity& p_entity){
      45. return p_entity.BuscarEnt(m_name);
      46. }
      47. bool operator()(Entity* p_entity){
      48. return p_entity != 0 && p_entity->BuscarEnt(m_name);
      49. }
      50. string m_name;
      51. }; //end clase Entity
      52. struct BusquedaParcDeEntity{
      53. BusquedaParcDeEntity(const string& p_str)
      54. :m_name(p_str){/*No hace nade*/}
      55. bool operator()(Entity& p_entity){
      56. return p_entity.BuscarParcial(m_name);
      57. }
      58. bool operator()(Entity* p_entity){
      59. return p_entity != 0 && p_entity->BuscarParcial(m_name);
      60. }
      61. string m_name;
      62. };
      63. } //end namespace Tyrim
      64. #endif
      Display All


      Thanks.
      Be a pointer my friend
    • Inheriting from an iterator or any STL data structure is a huge no-no. You should never do this; these objects are not meant to be used as base classes. Try to use an composition model rather than an inheritance model. I would clean that up and try again.

      -Rez