Is it possible using anonymous namespace on template in header files.

for example
  /// getPointerUnionTypeNum - If the argument has type PT1* or PT2* return
  /// false or true respectively.
  template <typename PT1, typename PT2>
  static inline int getPointerUnionTypeNum(PT1 *P) { return 0; }
  template <typename PT1, typename PT2>
  static inline int getPointerUnionTypeNum(PT2 *P) { return 1; }
  template <typename PT1, typename PT2>
  static inline int getPointerUnionTypeNum(...) { return -1; }

it's a peace of code comes from PointerUnion.h

can it change to be
namespace{
  template <typename PT1, typename PT2>
  inline int getPointerUnionTypeNum(PT1 *P) { return 0; }
  template <typename PT1, typename PT2>
  inline int getPointerUnionTypeNum(PT2 *P) { return 1; }
  template <typename PT1, typename PT2>
  inline int getPointerUnionTypeNum(...) { return -1; }
}

罗勇刚(Yonggang Luo) wrote:

for example
  /// getPointerUnionTypeNum - If the argument has type PT1* or PT2* return
  /// false or true respectively.
  template <typename PT1, typename PT2>
  static inline int getPointerUnionTypeNum(PT1 *P) { return 0; }
  template <typename PT1, typename PT2>
  static inline int getPointerUnionTypeNum(PT2 *P) { return 1; }
  template <typename PT1, typename PT2>
  static inline int getPointerUnionTypeNum(...) { return -1; }

it's a peace of code comes from PointerUnion.h

can it change to be
namespace{
  template <typename PT1, typename PT2>
  inline int getPointerUnionTypeNum(PT1 *P) { return 0; }
  template <typename PT1, typename PT2>
  inline int getPointerUnionTypeNum(PT2 *P) { return 1; }
  template <typename PT1, typename PT2>
  inline int getPointerUnionTypeNum(...) { return -1; }
}
  

Using the anonymous namespace in a header file is generally a very bad
idea. The problem is that it is a different namespace in every
translation unit. This can lead to subtle errors or simply undesirable
behavior.

Why would you want these functions in the AN anyway?

Sebastian