[Development] API style guide: scoped enum or not?

Jaroslaw Kobus Jaroslaw.Kobus at qt.io
Wed May 3 19:51:18 CEST 2023


"enum class" has one advantage over "enum" inside a "class" : you may forward declare the "enum class", while the other not. That's quite often case that your header must include the other header just because you use the "enum" in "class" in your API and nothing more.

Jarek

________________________________________
From: Development <development-bounces at qt-project.org> on behalf of Tor Arne Vestbø via Development <development at qt-project.org>
Sent: Wednesday, May 3, 2023 7:39 PM
To: Macieira, Thiago
Cc: development at qt-project.org
Subject: Re: [Development] API style guide: scoped enum or not?



On 3 May 2023, at 19:22, Thiago Macieira <thiago.macieira at intel.com> wrote:

I'd say that any new enumeration in the Qt namespace should be enum class, but
enums in classes may not be so if they're sufficiently descriptive already.

Agreed, and this is also what our current API design guide says:

<https://wiki.qt.io/API_Design_Principles#Naming_Enum_Types_and_Values>
API Design Principles - Qt Wiki<https://wiki.qt.io/API_Design_Principles#Naming_Enum_Types_and_Values>
wiki.qt.io<https://wiki.qt.io/API_Design_Principles#Naming_Enum_Types_and_Values>
[favicon.ico]<https://wiki.qt.io/API_Design_Principles#Naming_Enum_Types_and_Values>


tor arne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: favicon.ico
Type: image/vnd.microsoft.icon
Size: 5430 bytes
Desc: favicon.ico
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230503/ccf0d504/attachment.ico>


More information about the Development mailing list