template constructor not called for static member template object

D

devendra17sh

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
 
K

kfrank29.c

Hi Devendra!

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top