3

In mdart/mdart_function.h, function hash is defined.

inline nsaddr_t hash(nsaddr_t id) {
    bitset<ADDR_SIZE> tempAddress_ (id);
    bitset<ADDR_SIZE> address_;
    for(unsigned int i=0; i<ADDR_SIZE; i++) {
        if (tempAddress_.test(i)) {
            address_.set(ADDR_SIZE - 1 - i);
        }
    }
    address_.flip(ADDR_SIZE - 1);
    nsaddr_t temp = (nsaddr_t) address_.to_ulong();
#ifdef DEBUG
    fprintf(stdout, "\thash = %s\n", bitString(temp));
#endif
    return temp;
}

In another source file, the hash function is referenced with correct header include:

nsaddr_t dstAdd_ = hash(reqId);

However, there is another hash, std::hash and it throws error: reference to 'hash' is ambiguous when I build it.

Is there any way to specify which hash the source code tries to use? I know std::hash, but how about hash in the header file?

  • In the header, there is `#define __mdart_function__` defined. Can I use it as a namespace? Anyway, I will try both `__mdart_function__::hash` and `::hash`. Thanks. –  Jan 15 '14 at 05:00
  • 1
    No, you can't use a macro definition as a namespace. But you can define your own namespace by putting `namespace myspace { .... }` around your function declaration(s) and definition(s). You can then refer to your function using `myspace::hash()`. – jogojapan Jan 15 '14 at 05:01
  • 1
    also - if you didn't have `using namespace std` - it wouldn't be an issue – Glenn Teitelbaum Jan 15 '14 at 05:01

2 Answers2

5

You can use the namespace that the custom hash function is in to disambiguate it. If it's not in an explicit namespace, then just ::hash() will find it in the global namespace.

Tony Delroy
  • 102,968
  • 15
  • 177
  • 252
2

If your own hash implementation is in no particular namespace, you can use ::hash to refer to it.

jogojapan
  • 68,383
  • 11
  • 101
  • 131