debug message in a template class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomas

    debug message in a template class

    template <class T>
    class BufferQueue{
    public:
    int BufferQueue<T>: :pushToQueue(T pkt, int timeout);
    }

    template<class T>
    int BufferQueue<T>: :pushToQueue(T pkt, ACE_Time_Value *timeout){
    cout<<"in pushToQueue"<<e ndl; --------Line p
    return 0;
    }

    Suppose I have two instances BufferQueue<A_a , BufferQueue<B_b ;
    I want to know which instance I'm in by printing some debug messages
    out in Line p
    like
    "in pushToQueue of A", etc.

    How can I tell the compiler or change Line p to make it?
  • Barry

    #2
    Re: debug message in a template class

    On Sep 30, 2:46 pm, thomas <FreshTho...@gm ail.comwrote:
    template <class T>
    class BufferQueue{
    public:
              int BufferQueue<T>: :pushToQueue(T pkt, int timeout);
    >
    }
    >
    template<class T>
    int BufferQueue<T>: :pushToQueue(T pkt, ACE_Time_Value *timeout){
              cout<<"in pushToQueue"<<e ndl;              --------Line p
              return 0;
    >
    }
    >
    Suppose I have two instances BufferQueue<A_a , BufferQueue<B_b ;
    I want to know which instance I'm in by printing some debug messages
    out in Line p
    like
    "in pushToQueue of A", etc.
    >
    How can I tell the compiler or change Line p to make it?
    You can define a static memeber function like T::GetName() which
    returns
    the name of the class, so

    cout << "in pushToQueue " << T::GetName() << endl;

    Or you may have typeid(T).name( ) output as message.

    Comment

    • thomas

      #3
      Re: debug message in a template class

      >
      You can define a static memeber function like T::GetName() which
      returns
      the name of the class, so
      >
      cout << "in pushToQueue " << T::GetName() << endl;
      How can you write the "GetName" method?
      >
      Or you may have typeid(T).name( ) output as message.- Hide quoted text -
      >
      - Show quoted text -
      Yeah.. The typeid function should work. Thanks.

      Comment

      • James Kanze

        #4
        Re: debug message in a template class

        On Sep 30, 11:18 am, thomas <FreshTho...@gm ail.comwrote:

        [...]
        Or you may have typeid(T).name( ) output as message.- Hide
        quoted text -
        Yeah.. The typeid function should work. Thanks.
        It should, but whether it does or not is a quality of
        implementation issue. As far as the standard is concerned, an
        implementation which always returns "" is fully conforming. In
        practice, most implementations (with the notable exception of
        g++) do return something useful.

        --
        James Kanze (GABI Software) email:james.kan ze@gmail.com
        Conseils en informatique orientée objet/
        Beratung in objektorientier ter Datenverarbeitu ng
        9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

        Comment

        • Barry

          #5
          Re: debug message in a template class

          On Sep 30, 5:18 pm, thomas <FreshTho...@gm ail.comwrote:
          You can define a static memeber function like T::GetName() which
          returns
          the name of the class, so
          >
          cout << "in pushToQueue " << T::GetName() << endl;
          >
          How can you write the "GetName" method?
          >
          template <class T>
          struct MyClass
          {
          void MyFunc() const
          {
          std::cout << T::GetName() << std::endl;
          }
          };

          Here every instatiation of T is requred
          to have a static function named "GetName";

          struct T_type1
          {
          static char const* GetName() { return "T_type1"; }
          };

          int main()
          {
          MyClass<T_type1 c1;
          c1.MyFunc();
          }

          >
          >
          Or you may have typeid(T).name( ) output as message.- Hide quoted text -
          >
          - Show quoted text -
          >
          Yeah.. The typeid function should work. Thanks.

          Comment

          Working...