0
SimpleNode(int n)
{
 nodeId = n;
 NeighborCount = 0;
 arrNeighbors = 0;
 SimpleNode *arrNeighbors;       <------------
 arrNeighbors = new SimpleNode[n];
}

It gives error on arrowed line that; variable 'arrNeighbors' set but not used [-Wunused-but-set-variable]

  • Because it is set, but unused. hence the warning (or error, if you use -Werror flag). To suppress the warning use `-Wno-nused-but-set-variable` flag, or "use" your variable. – pptaszni Apr 27 '20 at 09:18
  • https://stackoverflow.com/questions/1486904/how-do-i-best-silence-a-warning-about-unused-variables https://stackoverflow.com/questions/15053776/how-do-you-disable-the-unused-variable-warnings-coming-out-of-gcc-in-3rd-party-c – pptaszni Apr 27 '20 at 09:19
  • before silencing the warning you should consider why you got warned. What is `arrNeighbors` good for? You set it but you do not use it. You really should either use it or remove it – 463035818_is_not_an_ai Apr 27 '20 at 09:20
  • 1
    I'm guessing that `arrNeighbors` is a member variable. Adding the type created a new, local, variable with the same name. – molbdnilo Apr 27 '20 at 09:21
  • 1
    you have two different `arrNeighbors` in your snippet. Is it possible that you actually did not want to declare a new variable with the same name as one of the members? – 463035818_is_not_an_ai Apr 27 '20 at 09:21
  • please exaplain what you think the last two lines are doing. currently we have to guess – 463035818_is_not_an_ai Apr 27 '20 at 09:22

0 Answers0