mardi 23 février 2016

static, constexpr, const - what do they mean?

I'm totally frustrated with these specifiers because I understand what they do when they're by themselves but I find them hard to understand when they're present with each other. For example, some code in the wild contained -

namespace{
static constexpr char const *Hello = { "HelloString", "WorldString"};
...
}

what does this even do?

  • why use static when you're already inside an anonymous namespace. And static inside classes makes sense ( unless you're writing C which lacks namespaces), without classes - why??
  • why use constexpr - there's no reason to use it here. wouldn't a simple const would do?
  • and then const *Hello doesn't makes sense to me. What is constant here? The strings or the pointer *Hello?

And worst of all, it compiles :/. Ofcourse it would compile because they're valid statements, but what does it even means?

Aucun commentaire:

Enregistrer un commentaire