C++ unused variable warning even when I returned it at the end of function

  • A+
Category:Languages
Table::Table(int n): maxGuests(n) {     int numGuests = 0; } int Table::maxOccupancy(void) {     return maxGuests; }  int Table::currentOccupancy(void) {     return numGuests; } 

As in the above code, I'm getting an unused numGuests warning, even after returning it at the end of my accessor. Why would that be?

Thanks :)

 


You create a local variable with the same name as a class member. Just remove int to get what you want:

Table::Table(int n): maxGuests(n) {     numGuests = 0; } 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: