Link to home
Start Free TrialLog in
Avatar of NSing9
NSing9Flag for United States of America

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
SOLUTION
Avatar of mifergie
mifergie
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of NSing9

ASKER

It sounds easy, but I have been stuck on this portion for quite sometime.  It's simple to an expert, but to a novice like myself, I have been at it for a few hours.
ASKER CERTIFIED SOLUTION
Avatar of Infinity08
Infinity08
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of NSing9

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 ?