Syntax error i think

Ok so Im trying to see if the vlaue is not a null assingment and I think that it is set up like this != null right or am I missing some thing;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <string>
#include <vector>
using namespace std;

#include "symboltable.h"


void SymbolTable::insert(string variable, double value)
{
	if(value != null){//see if value is not null
    const Symbol& symbol = Symbol(variable, value);
    elements.push_back(symbol);
	}
	else{
	cout << "Variables need to be initilized!" <<endl;
	}
}

double SymbolTable::lookUp(string variable) const
{
    for (int i = 0; i < elements.size(); i++)
        if (elements[i].variable == variable)
             return elements[i].value;
    return -1;
}
C++ is case-sensitive. The null value is NULL. However, a double will never be NULL; it is not a pointer.

Also, watch your indentation.

8
9
10
11
12
13
14
15
16
17
18
19
void SymbolTable::insert(string variable, double value)
{
        if (value != 0.0)
        {
                Symbol symbol(variable, value);
                elements.push_back(symbol);
        }
        else
        {
                cout << "Variables need to be initialized!" << endl;
        }
}

Line 12 doesn't make sense to work with a const reference -- you are only creating a local temporary. Technically, you needn't do that either -- you can just pass an unnamed temporary to push_back():
 
                elements.push_back( Symbol(variable, value) );

Finally, it is entirely possible that the user wanted an initial value of zero, so your check and error message seem questionable to me...

Hope this helps.
Thanks for the advice I am still prety new at this programing thing:)
Topic archived. No new replies allowed.