C
Christopher
I have the following errors, can someone explain how I accomplish the
pointer assignment here?
Error Message :
CQueue.cpp: In member function `void
cs3358Fall2003::circular_queue:ush(const
int&)':
CQueue.cpp:63: non-lvalue in assignment
CQueue.cpp:72: non-lvalue in assignment
CQueue.cpp: In member function `void cs3358Fall2003::circular_queue:op()':
CQueue.cpp:97: non-lvalue in assignment
// Function with errors
//////////////////////////////////////////////////////////////////////////
void circular_queue:ush(const value_type& entry)
{
// If the list has at least one entry
if(rear_ptr)
{
// Insert a new node and adjust pointers
node *new_ptr = new node(entry, rear_ptr->link());
// ERROR HERE! rear_ptr->link() = new_ptr;
rear_ptr = new_ptr;
}
// Otherwise the list was empty
else
{
// Insert a new node and point to itself
rear_ptr = new node(entry, NULL);
// ERROR HERE! rear_ptr->link() = rear_ptr;
}
// Increment the count
count ++;
}
// Header File for circular_qeue
#ifndef CIRCULAR_QUEUE_H
#define CIRCULAR_QUEUE_H
#include <cstdlib> // provides size_t
#include "Node0.h"
namespace cs3358Fall2003
{
class circular_queue
{
public:
//TYPEDEF
typedef node::value_type value_type;
typedef size_t size_type;
// CONSTRUCTORS and DESTRUCTOR
circular_queue();
circular_queue(const circular_queue& source);
~circular_queue();
// MODIFICATION functions
void push(const value_type& entry);
void pop();
const circular_queue& operator=(const circular_queue& source);
// CONSTANT functions
size_type size() const;
bool empty() const;
value_type front() const;
value_type peek(size_type n) const;
private:
node *rear_ptr; // points to rear of queue
size_type count; // number of items in the queue
};
}
#endif
// Header file for Node0
#ifndef NODE0_H
#define NODE0_H
namespace cs3358Fall2003
{
class node
{
public:
// TYPEDEF
typedef int value_type;
// CONSTRUCTOR
node(const value_type& init_data = value_type(),
node* init_link = 0);
// Member functions to set the data and link fields:
void set_data(const value_type& new_data);
void set_link(node* new_link);
// Constant member function to retrieve the current data:
value_type data() const;
// Two slightly different member functions to retreive
// the current link:
const node* link() const;
node* link();
private:
value_type data_field;
node* link_field;
};
}
#endif
Thanx,
Chris
pointer assignment here?
Error Message :
CQueue.cpp: In member function `void
cs3358Fall2003::circular_queue:ush(const
int&)':
CQueue.cpp:63: non-lvalue in assignment
CQueue.cpp:72: non-lvalue in assignment
CQueue.cpp: In member function `void cs3358Fall2003::circular_queue:op()':
CQueue.cpp:97: non-lvalue in assignment
// Function with errors
//////////////////////////////////////////////////////////////////////////
void circular_queue:ush(const value_type& entry)
{
// If the list has at least one entry
if(rear_ptr)
{
// Insert a new node and adjust pointers
node *new_ptr = new node(entry, rear_ptr->link());
// ERROR HERE! rear_ptr->link() = new_ptr;
rear_ptr = new_ptr;
}
// Otherwise the list was empty
else
{
// Insert a new node and point to itself
rear_ptr = new node(entry, NULL);
// ERROR HERE! rear_ptr->link() = rear_ptr;
}
// Increment the count
count ++;
}
// Header File for circular_qeue
#ifndef CIRCULAR_QUEUE_H
#define CIRCULAR_QUEUE_H
#include <cstdlib> // provides size_t
#include "Node0.h"
namespace cs3358Fall2003
{
class circular_queue
{
public:
//TYPEDEF
typedef node::value_type value_type;
typedef size_t size_type;
// CONSTRUCTORS and DESTRUCTOR
circular_queue();
circular_queue(const circular_queue& source);
~circular_queue();
// MODIFICATION functions
void push(const value_type& entry);
void pop();
const circular_queue& operator=(const circular_queue& source);
// CONSTANT functions
size_type size() const;
bool empty() const;
value_type front() const;
value_type peek(size_type n) const;
private:
node *rear_ptr; // points to rear of queue
size_type count; // number of items in the queue
};
}
#endif
// Header file for Node0
#ifndef NODE0_H
#define NODE0_H
namespace cs3358Fall2003
{
class node
{
public:
// TYPEDEF
typedef int value_type;
// CONSTRUCTOR
node(const value_type& init_data = value_type(),
node* init_link = 0);
// Member functions to set the data and link fields:
void set_data(const value_type& new_data);
void set_link(node* new_link);
// Constant member function to retrieve the current data:
value_type data() const;
// Two slightly different member functions to retreive
// the current link:
const node* link() const;
node* link();
private:
value_type data_field;
node* link_field;
};
}
#endif
Thanx,
Chris