Thread: Expected primary expression?

  1. #16
    Registered User
    Join Date
    Sep 2007
    Posts
    100
    Thanks for the help! I have a new question now. When I run my program it unexpectantly ends - "This application has requested the runtime to terminate it in an unusual way". After putting in debugging statements I have found the root of this error to be whenever I call myNodePool[]. For example, here is the first occurance of myNodePool, in main.cpp:

    Code:
    int main(int argc, char *argv[])
    {
        ifstream    fileStream;
        char        *fileName;
        string      line;
        int         lineNo;
        bst         tree;
       
    
        [clip]
    
        for(int ii = 0; ii < SIZE-1; ii++)
        {
            cout << "ii = " << ii << "\n";
            cout << "checking Nodes...\n";
            cout << "myNodePool[" << ii << "].left = " << tree.myNodePool[ii].left << "\n"; // terminates
            cout << "myNodePool[" << ii << "].right = " << tree.myNodePool[ii].right << "\n";
        }
    My constructor for NodePool looks like:

    Code:
    NodePool::NodePool(void)
    {
        free = 0;
        
        for(int ii = 0; ii < SIZE-1; ii++)
        {
            pool[ii].left = 2 * ii;
            pool[ii].right = (2 * ii) + 1;
            pool[ii].used = false;
        }
    
        pool[SIZE-1].left = -1;
        pool[0].right = -1;
    }
    Which should populate all nodes (in my case 10,000) with appropriate integers as defined by 2ii and 2ii+1. I'm assuming that this constructor is never being called and thus when I try to use myNodePool, nothing is in it. In bst.h I call NodePool myNodePool:

    Code:
    using namespace std;
    
    class bst
    {
    
    public:	
    
    	bst(void);
    
    	bool empty(void);
    
    	int insert (string word, int lineno);
    
    	int search (string word);
    
    	void inorder (ostream & out);
    
        string modifyWord(string ss);
    
        NodePool myNodePool;
    };
    So shouldn't creating a new NodePool object automatically call the default NodePool constructor, thus populating my Node array?
    "I don't fail - I succeed at finding things that don't work"
    Website Promotion Techniques @AbstractPromotion.com

  2. #17
    Registered User
    Join Date
    Sep 2007
    Posts
    100
    Update: apparently the NodePool default constructor is being called and my node .left and .right values are being saved - I added a cerr output at the start of the method to print "NodePool Called" and sure enough that is the first thing that prints out, before my program terminates. So then why am I not able to call myNodePool? Any ideas?
    Last edited by Beowolf; 11-10-2007 at 11:32 AM.
    "I don't fail - I succeed at finding things that don't work"
    Website Promotion Techniques @AbstractPromotion.com

  3. #18
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What does the declaration of pool look like inside the NodePool class?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expected primary expression before "." token
    By melodious in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 04:39 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM