Hi .... i'm getting the following error " 'buildListForward undeclared' when trying to compile this program.
Please help !

//Linked lists
//Pg.288
#include <iostream>
using namespace std;

    nodeType* buildListForward();
    
    
    int main()
{

    buildListForward();

    nodeType* buildListForward()
    {
        nodeType *first, *newnode, *last;
        int num;
        
        cout << "Enter a list of integers ending with -999.\n";
        cin  >> num;
        first = NULL;
        
        while (num != -999)
        {
                newNode = new nodeType;
                assert(newNode !=NULL);
                
                newNode ->info = num;
                newNode ->link = NULL;
                
                if(first == NULL)
                {
                  first = newNode;
                  last = newNode;
                }
                else
                {
                  last -> link = newNode;
                  last = newNode;
                }
                cin >> num;
        }
    };

1) Functions don't nest (you can't define buildListForward inside main.
2) You can't use a type that doesn't exist (you haven't defined nodeType).
3) Check your spelling. C++ is case sensitive and very picky about syntax.
4) If you say you're going to return a value from a function, do so.
5) Include <cassert> if you want to use the assert macro.

//Linked lists
//Pg.288
#include <cassert>
#include <iostream>
using namespace std;

struct nodeType {
  int info;
  nodeType *link;
};

nodeType* buildListForward();

int main()
{
  buildListForward();
}

nodeType* buildListForward()
{
  nodeType *first, *newNode, *last;
  int num;

  cout << "Enter a list of integers ending with -999.\n";
  cin  >> num;
  first = NULL;

  while (num != -999)
  {
    newNode = new nodeType;
    assert(newNode !=NULL);

    newNode ->info = num;
    newNode ->link = NULL;

    if(first == NULL)
    {
      first = newNode;
      last = newNode;
    }
    else
    {
      last -> link = newNode;
      last = newNode;
    }

    cin >> num;
  }

  return first;
}
This article has been dead for over six months. Start a new discussion instead.