Search code examples
c++templatesc++98compile-time-constantconstant-expression

constant expression function in c++98


I have following problem with c++98 constant expressions. Here is an example for an template struct.. which will receive the size at compile time..

Is it somehow possible to get this size as constant expression without c++11 constexpr? Take a look at GetCount()...

    template <typename ValueType, UInt32 size>
    struct FixedArray
    {
       ValueType mArr[size > 0 ? size : 1];
       UInt32 GetCount() const { return size; }

      ...
      other code
      ..
    }

I would like to be able to do something like this:

FixedArray<int , 10> a;
FixedArray<int , a.GetSize()> b;

Edit:

I couldn't find a way for C++ 98, seems like it isn't possible at all.


Solution

  • Seems like there is no way to do this in C++ 98, it simply doesn't work.