Imagine I have this class.
Foo.hpp:
#pragma once
#include <cstdint>
class Foo {
static const std::size_t Size;
std::uint32_t buffer[Size];
};
I want to calculate Size in the source file, so I don't need to include the files needed for the calculation in the header.
Foo.cpp:
#include "Foo.hpp"
#include "Lib1.hpp" // -> #define Size1 1
#include "Lib2.hpp" // -> #define Size2 2
const std::size_t Foo::Size = Size1 + Size2;
Doing so I get the following error:
In file included from src\Foo.cpp:1:
include/Foo.hpp:6:24: error: size of array 'buffer' is not an integral constant-expression
30 | std::uint32_t buffer[Size];
| ^~~~
Is it possible to externaly declare a static const class member? If yes, how?