F
F
floppa3222021-12-05 15:53:40
C++ / C#
floppa322, 2021-12-05 15:53:40

Is it possible to access a static field of a class template without instantiating the template?

Is there a syntax construct in C++ to access a public static constant in a class template from the outside?

Example:

template <typename T, int32_t maxSize>
class CircularBuffer
{
private:

 /* Some code */

public:
static const int32_t  MEMBER_TO_BE_ACCESSIBLE_OUTSIDE = 0;
};


Because writing something like
CircularBuffer<int, 0>::MEMBER_TO_BE_ACCESSIBLE_OUTSIDE
, adding "dummy" template parameters is somehow too crutch.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergio, 2021-12-05
@Lite_stream

class CircularBufferBase
{
public:
    static const int32_t MEMBER_TO_BE_ACCESSIBLE_OUTSIDE = 0;
};

template <typename T, int32_t maxSize>
class CircularBuffer : public CircularBufferBase {
    ...
}

CircularBufferBase::MEMBER_TO_BE_ACCESSIBLE_OUTSIDE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question