template constructor not called for static member template object

Discussion in 'C++' started by devendra17sh@gmail.com, Apr 12, 2013.

  1. Guest

    Hello,
    This compiles, but constructor initialization doesn't happen. Any clues?

    template<typename T, int buff_size>
    class CRingBuffer
    {
    protected:
    int const _buffer_size;
    T _buffer[buff_size];
    T* _back;
    T* _front;

    public:
    CRingBuffer() : _buffer_size(buff_size)
    {
    _back = _buffer; <-- Not executed
    _front = NULL;
    }
    void get()
    {
    <clipped>
    }
    };

    struct SErr
    {
    char *desc;
    }

    class CErrorHandler
    {
    protected:
    CErrorHandler() {};
    static CRingBuffer<SErr,10> m_errLog;
    };

    CRingBuffer<SErr,10> CErrorHandler::m_errLog; <-- ?

    class Backend : public CErrorHandler
    {
    void func()
    {
    SErr errObj = _errLog.get();
    }
    }

    Thanks & regards,
    Devendra
     
    , Apr 12, 2013
    #1
    1. Advertising

  2. Guest

    Hi Devendra!

    Not an asnwer ro your question, but a minor question
    of my own.

    On Thursday, April 11, 2013 11:27:04 PM UTC-4, wrote:
    > Hello,
    >
    > This compiles, but constructor initialization doesn't happen. Any clues?


    (No, sorry.)

    >
    > template<typename T, int buff_size>
    > class CRingBuffer
    > {
    > protected:
    > int const _buffer_size;
    > T _buffer[buff_size];


    My question: Why do you introduce "_buffer_size"?
    Why not just use "buff_size"?

    Is this purely a stylistic thing? I see you have
    _buffer_size as a protected member. Even though
    you don't derive from CRingBuffer in the example
    you posted, is the purpose of _buffer_size to expose
    buff_size to classes that might get derived in the
    future?

    (This is just for me to learn a little more about
    templates and some of the idioms people use with
    them.)

    > T* _back;
    > T* _front;
    >
    > public:
    > CRingBuffer() : _buffer_size(buff_size)
    > {
    > _back = _buffer; <-- Not executed
    > _front = NULL;
    > }
    > ...
    >
    > Thanks & regards,
    >
    > Devendra


    Best.


    K. Frank
     
    , Apr 12, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Nicol
    Replies:
    3
    Views:
    473
    Craig Nicol
    Aug 26, 2004
  2. tropos
    Replies:
    3
    Views:
    465
  3. er
    Replies:
    2
    Views:
    332
  4. Generic Usenet Account
    Replies:
    10
    Views:
    2,246
  5. dolphin
    Replies:
    3
    Views:
    1,349
    Pete Becker
    Dec 5, 2007
Loading...

Share This Page