Sign in to follow this  
Khao

What is wrong with that class?

Recommended Posts

Hey folks, I'm facing a weird problem here. I'm trying to make a 'static' class that will contain my maps and hash tables for users, since they exist only once in the program and they need to be accessible from any place of the code I though static was the best way to do this. Although when I include it from more than 1 file, I get 'Lists' has not been declared errors. I can't see what's wrong in this code because I have another static class called MysqlManager which is included in many files and I do not receive the error for the MysqlManager class with only static members. Here's List.hpp
#ifndef LISTS_HPP
#define LISTS_HPP

#include <map>
#include <ext/hash_map>
#include <google/dense_hash_map>
#include "User.hpp"

struct eqstr
{
   bool operator()(const char* s1, const char* s2) const
   {
      return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
   };
};

class Lists
{
public:
   static dense_hash_map<const char*, int, __gnu_cxx::hash<const char*>, eqstr> UsernameToUID;
   Lists(){};
   static void initialize()
   {
      UsernameToUID.set_empty_key("---");
   };

   static map<int, User*> UIDtoUser;
};

map<int, User*> Lists::UIDtoUser;
dense_hash_map<const char*, int, __gnu_cxx::hash<const char*>, eqstr> Lists::UsernameToUID(10000);

#endif

I need to include this class into many files because the Server, Lobby and User classes need to have access to Lists::UsernameToUID or Lists::UIDtoUser. My MysqlManager class is the same as this one, with static members only and I can include it in different files with no problem.. Anybody knows why I get this error?

Share this post


Link to post
Share on other sites
Quote:
Original post by Khao
I'm trying to make a 'static' class that will contain my maps and hash tables for users, since they exist only once in the program and they need to be accessible from any place of the code

Not really a big deal here, but do they? Why does your sound subsystem need to know about the maps? Why do you need access to the maps when reading input from the player? "It needs to be accessible everywhere" is usually a sign of bad design.

But like I said, probably not a big deal here. Just thought I'd mention that you're basing your decisions on a false assumption. These maps do not need to be accessible everywhere.

Share this post


Link to post
Share on other sites
Right, it's really easy for me to restructure the other class to not use Lists, but I am still wondering as why does my MysqlManager class can be included in many other files, and Lists cannot :\

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this