1

I have a program that implements a structure in a linked list. I am getting an error in the main that is saying "invalid use of struct Node::date." I cannot figure out. My professors don't know either. Any help would be appreciated along with an explanation so I know why it is doing this.

#include <iostream>
#include <cstddef>
#include <string>
using namespace std;

struct date
{
   int day;
   int month;
   int year;
};

struct Node
{
    string item;
    int count;
    Node *link;
    struct date;
};

typedef Node* NodePtr;
void head_insert(NodePtr& head, string an_item, int a_number, date a_date);
void show_list(NodePtr& head);

int main()
{
    date tea_date, jam_date, rolls_date;
    rolls_date.day = 8;
    rolls_date.month = 10;
    rolls_date.year = 2003;

    jam_date.day = 9;
    jam_date.month = 12;
    jam_date.year = 2003;

    tea_date.day = 1;
    tea_date.month = 1;
    tea_date.year = 2010;

    NodePtr head = NULL;
    head_insert(head, "Tea", 2, tea_date);
    head_insert(head, "Jam", 3, jam_date);
    head_insert(head, "Rolls", 10, rolls_date);

    show_list(head);
    system("PAUSE");
    return 0;
}

void head_insert(NodePtr& head, string an_item, int a_number, date a_date)
{
    NodePtr temp_ptr;

    temp_ptr = new Node;
    temp_ptr-> item = an_item;
    temp_ptr-> count = a_number;
    temp_ptr-> date = a_date;

    temp_ptr->link = head;
    head = temp_ptr;
}

void show_list(NodePtr& head)
{
    NodePtr here = head;

    while (here != NULL)
    {
        cout << here-> item << "\t";
        cout << here-> count << endl;

        here = here->link;
    }
}
digital_revenant
  • 3,274
  • 1
  • 15
  • 24
user2837034
  • 207
  • 1
  • 6
  • 11
  • 4
    What college is it? I'd like to know whose professors teach C++ but can't spot this bug. – Beta Oct 16 '13 at 15:11
  • 1
    @Beta They also appear to teach [`using namespace std;`](http://stackoverflow.com/q/1452721/1171191), [`std::endl`](http://kuhllib.com/2012/01/14/stop-excessive-use-of-stdendl/), and [`system("pause");`](http://www.gidnetwork.com/b-61.html), although it seems to be distressingly common that people on here have been taught bad practices by professors. I think they just teach the same thing every year, and never write real code or learn anything new. They are too busy worrying about their other academic interests. – BoBTFish Oct 16 '13 at 15:22
  • [(although I would hope there is at least one professor teaching `C++` who knows what he is talking about)](http://www.stroustrup.com/) – BoBTFish Oct 16 '13 at 15:25

1 Answers1

3

This is just a declaration of a struct called date:

struct date;

What you need is to give your Node a date instance:

struct Node
{
  string item;
  int count;
  Node *link;
  date date_; // Node has a date called date_
};
juanchopanza
  • 223,364
  • 34
  • 402
  • 480