Sample structure:
typedef struct tagExportSettings
{
COLORREF crHeading{};
COLORREF crEvenBack{};
COLORREF crOddBack{};
COLORREF crHighlight{};
COLORREF crDate{};
COLORREF crEvent{};
COLORREF crEmpty{};
COLORREF crNotes{};
} EXPORT_SETTINGS_S;
Visual Assist says:
typedefcan be converted tousingdeclaration.
Is there any real benefit of making this code change?
All my code in the software uses EXPORT_SETTINGS_S so I don’t want to break that syntax.
>Solution :
Even better is to use neither. One type name should be enough. Pick either tagExportSettings or EXPORT_SETTINGS_S and stick with it. Example:
struct tagExportSettings
{
// ...
};
But, 1. All my code in the software uses
EXPORT_SETTINGS_S
As I said, pick either name. If you use EXPORT_SETTINGS_S, then name the class as EXPORT_SETTINGS_S:
struct EXPORT_SETTINGS_S
{
// ...
};
If something still refers to tagExportSettings, then refactor the code to use the canonical name.
But more generally, using is preferred to typedef because it’s more readable. There are at least two reasons for it:
-
With
typedefsyntax it isn’t intuitive which is the old name and which is the new alias:typedef new_or_old old_or_new; // old_or_new is the new aliasusingis intuitive through familiar pattern of initialisation:using intuitively_alias = intuitively_old_name; -
typedefsyntax is difficult for a programmer to parse in case of compound names because the alias is "interleaved":// alias for void() typedef void function(); using function = void();