NSing9
asked on
How do I modify a C++ class to display a warning for variables that are initialized but never used?
How do I modify a C++ class to display a warning for variables that are initialized but never used? My program accepts an expression and checks, among other things, that all variables are initialized. Currently, it throws an error when there is an unitialized variable, but how do I get it to display a warning for a variable that is not used and display that variables name in the output?
Example:
I enter: (2/3), x = 1;
It should display a warning along with the variable name and correct value:
Warning: Unreferenced Variable x Value = 0.666667
Right now it is only displaying: Value = 0.666667
I have included a few of the classes that I have created so far but can't figure out how to add this piece to warn when unreferenced variables are encountered. I have also include the UninitializedException.h file to show how I currently throw an exception for the uninitialized variables.
symboltable.cpp
main.cpp
variable.cpp
UninitializedException.h
Example:
I enter: (2/3), x = 1;
It should display a warning along with the variable name and correct value:
Warning: Unreferenced Variable x Value = 0.666667
Right now it is only displaying: Value = 0.666667
I have included a few of the classes that I have created so far but can't figure out how to add this piece to warn when unreferenced variables are encountered. I have also include the UninitializedException.h file to show how I currently throw an exception for the uninitialized variables.
symboltable.cpp
main.cpp
variable.cpp
UninitializedException.h
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
lol. How about that for synchronization :)
Haha, you always beat me by about 30 seconds. Maybe I should stop adding a signature to speed up :p
ASKER
Gentlemen, both your explanations make perfect since, but I am stuck on the coding portion. I have never program in C++ and seem to be struggling with the basic concepts. Are there any suggestions with the required code to make this work?
I'm not sure how to make the suggestions clearer, but obviously something is missing in our explanations.
Could you show us where you are stuck ?
Could you show us where you are stuck ?
ASKER