Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

invalid initializer for structured binding declaration

How should I fix this error? Should I use a const std::tuple<int, int, char> instead?

constexpr auto [ Y_AxisLen, X_AxisLen, fillCharacter ] { 36, 168, ' ' };

This gives errors like:

error: structured binding declaration cannot be 'constexpr'
  434 |         constexpr auto [ Y_AxisLen, X_AxisLen, fillCharacter ] { 36, 168, ' ' };

 error: invalid initializer for structured binding declaration
  434 |         constexpr auto [ Y_AxisLen, X_AxisLen, fillCharacter ] { 36, 168, ' ' };

Y_AxisLen and X_AxisLen should be of type int and fillCharacter should be a char.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  • structure binding isn’t allowed to be constexpr now.
  • structure binding can only be applied to the following cases.
    • array
    • tuple-like
    • structure data members

ref: https://en.cppreference.com/w/cpp/language/structured_binding

If you must use structure binding, use std::make_tuple

const auto [ Y_AxisLen, X_AxisLen, fillCharacter ] = std::make_tuple(36, 168, ' ');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading