Why aren't static const floats allowed?

后端 未结 6 2184
无人及你
无人及你 2020-11-29 02:25

I have a class which is essentially just holds a bunch of constant definitions used through my application. For some reason though, longs compile but floa

6条回答
  •  有刺的猬
    2020-11-29 03:04

    See Stroustrup's explanation. Relevant quote:

    A class is typically declared in a header file and a header file is typically included into many translation units. However, to avoid complicated linker rules, C++ requires that every object has a unique definition. That rule would be broken if C++ allowed in-class definition of entities that needed to be stored in memory as objects. See D&E for an explanation of C++'s design tradeoffs.

提交回复
热议问题