Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   template constructor not called for static member template object (http://www.velocityreviews.com/forums/t959669-template-constructor-not-called-for-static-member-template-object.html)

devendra17sh@gmail.com 04-12-2013 03:27 AM

template constructor not called for static member template object
 
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

kfrank29.c@gmail.com 04-12-2013 01:00 PM

Re: template constructor not called for static member template object
 
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, devend...@gmail.com 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


All times are GMT. The time now is 07:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.