jeudi 8 décembre 2022

static constexpr C++ [duplicate]

Why does a static constexpr array work and a static constexpr std::array not? C++11

struct FixedParameters{
  using LookUpTable = std::array<std::pair<float, float>, 1>;
  static constexpr LookUpTable lookUpTable};
  static constexpr std::pair<float, float> array[]=0.1;
  static constexpr int value = 42;
};
int main(){
  std::cout << FixedParameters::lookUpTable[0].second << std::endl; //error
  std::cout << FixedParameters::array[0].second << std::endl; // ok
  std::cout << FixedParameters::value << std::endl; // ok
}
// PS D:\...\Constexpr> clang++ *.cpp
// lld-link: error: undefined symbol: FixedParameters::lookUpTable
// >>> referenced by C:\../constexpr-d4252b.o:(.refptr._ZN15FixedParameters11lookUpTableE)
// clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Aucun commentaire:

Enregistrer un commentaire