Search code examples
c++structtypedefusing

how to change typedef struct declaration into a using alias struct?


my struct is defined like this:

typedef struct
{
  int foo;
  char key;
} myStruct;

and I would like to change it to

using struct myStruct = {
      int foo;
      char key;
    } myStruct;

but it seems that something is wrong with it


Solution

  • Yes, you can replace

    typedef struct
    {
      int foo;
      char key;
    } myStruct;
    

    by

    using myStruct = struct
    {
      int foo;
      char key;
    };
    

    But it doesn't make any sense, and you will just confuse readers or possible maintainers of the code.

    The established way to go is:

    struct myStruct
    {
      int foo;
      char key;
    };