-2

warning ? char.cpp warning

how can i resolve this warning? Information message with warning;

char.cpp: In constructor 'switch_channel_info::switch_channel_info()':
char.cpp:7370:6: warning: 'switch_channel_info::secs' will be initialized after [-Wreorder]
 7370 |  int secs;
      |      ^~~~
char.cpp:7369:22: warning:   'DynamicCharacterPtr switch_channel_info::ch' [-Wreorder]
 7369 |  DynamicCharacterPtr ch;
      |                      ^~
char.cpp:7374:2: warning:   when initialized here [-Wreorder]
 7374 |  switch_channel_info()

The warning part is as follows.

EVENTINFO(switch_channel_info)
{
    DynamicCharacterPtr ch;
    int secs;
    long newAddr;
    WORD newPort;

    switch_channel_info()
        : secs(0),
        ch(),
        newAddr(0),
        newPort(0)
    {
    }
};
Rouge
  • 1
  • 2
  • See [this](https://stackoverflow.com/questions/1828037/whats-the-point-of-g-wreorder). And paste the warning as text as well. – cigien Oct 13 '20 at 22:11
  • 1
    Does this answer your question? [Constructor initialization-list evaluation order](https://stackoverflow.com/questions/1242830/constructor-initialization-list-evaluation-order) – Retired Ninja Oct 13 '20 at 22:14
  • 1
    Please post code, errors, sample data or textual output here as plain-text, not as images that can be hard to read, can’t be copy-pasted to help test code or use in answers, and are barrier to those who depend on screen readers. You can edit your question to add the code in the body of your question. For easy formatting use the `{}` button to mark blocks of code, or indent with four spaces for the same effect. The contents of a **screenshot can’t be searched, run as code, or copied and edited to create a solution.** – tadman Oct 13 '20 at 22:15
  • It was arranged in detail. – Rouge Oct 13 '20 at 22:23
  • Have you tried changing the order in the constructor list? – tadman Oct 13 '20 at 22:26
  • how can you give an example exactly? – Rouge Oct 13 '20 at 22:28

1 Answers1

0

In this section, when I replace the secs variable with the ch variable, the warning disappeared and the problem was solved.

DynamicCharacterPtr ch;
int secs;
long newAddr;
WORD newPort;

I changed it as follows and the problem was solved.

int secs;
DynamicCharacterPtr ch;
long newAddr;
WORD newPort;
Rouge
  • 1
  • 2
  • The order in the constructor list should match the order in the constructor, so you can either adjust the structure, as you have here, or the constructor list. – tadman Oct 13 '20 at 22:56