Thread: Expression cannot be evaluated

  1. #1
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74

    Expression cannot be evaluated

    This is the error I get when in the debugger of VC++, but the program compiles fine. When I run it, there is an immediate error and I have to close the program. Any ideas as to why this is happening?

    Code:
    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    class BTree_Data{
    	private:
    		int location, personType;
    	public:
    		BTree_Data(){ location = 0; personType = 0; }
    		~BTree_Data(){}
    
    		BTree_Data *rightChild;
    		BTree_Data *leftChild;
    
    		//Methods
    		void setLocation(int i) { location = i; } //error here
    		int getLocation(void) { return location; } //here too
    		void setPersonType(int i) { personType = i; } //and here
    		int getPersonType(void) { return personType; } //last one
    };
    
    void addChild(BTree_Data root, BTree_Data iterator);
    void delChild(BTree_Data root, BTree_Data iterator);
    void printTree(BTree_Data root, BTree_Data iterator);
    
    int main(void)
    {
    	int choice;
    	BTree_Data *root = 0, *iterator = 0;
    	root->setLocation(0);
    	root->setPersonType(0);
    	root->rightChild = NULL;
    	root->leftChild = NULL;
    	iterator = root;
    	
    	cout << "Menu:\n" <<
    			"\t1: Add a child\n" <<
    			"\t2: Delete a child\n" <<
    			"\t3: Print tree\n" <<
    			"\t4: Exit\n\n" <<
    			"::>";
    	choice = cin.get();
    
    	switch(choice){
    		case 1:
    			addChild(*root, *iterator);
    			break;
    		case 2:
    			delChild(*root, *iterator);
    			break;
    		case 3:
    			printTree(*root, *iterator);
    			break;
    		case 4:
    			exit(0);
    			break;
    		default:
    			cout << "Invalid input, please try again\n";
    			break;
    	}
    
    	return 0;
    }
    
    void addChild(BTree_Data root, BTree_Data iterator){
    	cout << "addChild() Function" << endl;
    }
    
    void delChild(BTree_Data root, BTree_Data iterator){
    	cout << "delChild() Function" << endl;
    }
    
    void printTree(BTree_Data root, BTree_Data iterator){
    	cout << "printTree() Function" << endl;
    }
    pointer = NULL

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    It's because you're trying to use member functions of objects that don't exist -

    BTree_Data *root = 0, *iterator = 0;
    root->setLocation(0);
    root->setPersonType(0);

    If you want to use root->setLocation(); or root->setPersonType(); then root must point at a BTree_Data object.
    zen

  3. #3
    Registered User *pointer's Avatar
    Join Date
    Oct 2001
    Posts
    74
    How embarassing, I forgot to use new.
    pointer = NULL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with making a Math Expression DLL
    By MindWorX in forum C Programming
    Replies: 19
    Last Post: 07-19-2007, 11:37 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. recursion error
    By cchallenged in forum C Programming
    Replies: 2
    Last Post: 12-18-2006, 09:15 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Expression Evaluator Contest
    By Stack Overflow in forum Contests Board
    Replies: 20
    Last Post: 03-29-2005, 10:34 AM