class & struct....Questions

That is my class definition, but I am not sure how I am going to access the item of the struct (PriorityQueue::Item data) also how I am going to fill it out.
The function insert will inser an item and I will provide the priority, the highest priority will set the item to the head_ptr.
questions:
How to access the PriorityQueue::Item data?
How to fill the PriorityQueue::Item data?




#ifndef PQUEUE_H
#define PQUEUE_H
#include <stdlib.h> // Provides size_t

struct Node; // This will be completely defined below.

class PriorityQueue
{
public:
typedef int Item;
PriorityQueue( );
PriorityQueue(const PriorityQueue& source);
~PriorityQueue( );
void operator =(const PriorityQueue& source);
size_t size( ) const { return many_nodes; }
void insert(const Item& entry, unsigned int priority);
Item get_front( );
bool is_empty( ) const { return many_nodes == 0; }
private:

Node* head_ptr;
size_t many_nodes;
};

struct Node
{ // Node for a linked list
PriorityQueue::Item data;
unsigned int priority;
Node *link;
};

#endif
First, you should know by now to use code tags.

You need to create an object in main of type PriorityQueue. Use this objects functions to get at member variables. Generally all of the work to do with the object should be carried out by member functions of that class. So within a class function, you can refer to members of the Node struct using the normal dot notation, or the -> operator if you have a pointer.

Your Node is a bit weird - you have a class member inside it !!! The Node struct should just have the variables that make it a node, only. The class should then do operations with the node.
Last edited on
Thanks but im not sure how to enter data to
PriorityQueue::Item data;

I create a
Node ptr;
ptr->data; //but does not work, I knew it was not going to work, but not sure how to do it.
TheIdeasMan wrote:
You need to create an object in main of type PriorityQueue


In your class function - a constructor or whatever, why can't you do this:

ptr->data = 1;
Topic archived. No new replies allowed.