У меня класс:
Код: Выделить всё
template requires (SizeOfEachStack > 0)
class ThreeStack
{
public:
struct StackProperties
{
std::size_t min_index{0};
std::size_t max_index{0};
std::size_t current_index{0};
};
ThreeStack()
{
for(std::size_t stack_number = 0; stack_number < num_of_stacks; stack_number++)
{
stack_properties.at(stack_number).min_index = stack_number * SizeOfEachStack;
stack_properties.at(stack_number).current_index = stack_properties.at(stack_number).min_index;
stack_properties.at(stack_number).max_index = stack_properties.at(stack_number).min_index + SizeOfEachStack - 1;
}
};
// Print function to print the internal arrays.
void print_internal_arrays()
{
for(std::size_t stack_number = 0; stack_number < num_of_stacks; stack_number++)
{
std::print("Stack {}: {}\n", stack_number, stack_properties.at(stack_number));
}
}
private:
static constexpr size_t num_of_stacks{3};
std::array stack_properties{};
};
Код: Выделить всё
// Create a std::formatter for the ThreeStack::StackProperties struct for any ThreeStack.
template
struct std::formatter
{
constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
template
auto format(const ThreeStack::StackProperties& stack_properties, FormatContext& ctx)
{
return format_to(ctx.out(), "min_index: {}, max_index: {}, current_index: {}", stack_properties.min_index, stack_properties.max_index, stack_properties.current_index);
}
};
Код: Выделить всё
:43:78: error: type/value mismatch at argument 1 in template parameter list for 'template struct std::formatter'
43 | struct std::formatter
| ^
:43:78: note: expected a type, got 'ThreeStack::StackProperties'
:43:13: error: template class without a name
43 | struct std::formatter
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Compiler returned: 1
Подробнее здесь: https://stackoverflow.com/questions/792 ... nt-support