473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

nonlvalue error

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::push(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::pop()':
CQueue.cpp:97: non-lvalue in assignment

// Function with errors
//////////////////////////////////////////////////////////////////////////
void circular_queue::push(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
Jul 19 '05 #1
2 7306
Christopher wrote:
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::push(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::pop()': CQueue.cpp:97: non-lvalue in
assignment

// Function with errors
//////////////////////////////////////////////////////////////////////////
void circular_queue::push(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->link() returns a temporary node*, which is not an lvalue, i.e.
you can't assign to it. Anyway, why would you want to? The temporary is
destroyed immediately afterwards, so the assignment would be useless
anyway.
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;
Same as above.
}

// 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


--
Never wondered why a carrot is more orange than an orange?

Jul 19 '05 #2


Christopher wrote:

// Function with errors
//////////////////////////////////////////////////////////////////////////
void circular_queue::push(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;


Lets look at link()

node* link();

Hmm. link returns a pointer. Even if you did not show the implementation,
I guess it does:

node* node::link()
{
return link_field;
}

Right?

So what does link() do? It returns the current value in link_field.
What to do with that value? You try to assign a new value to it.
But hey, the value returned by link() is just a number, a temporary.
What good does it, if you assign a new value to it? You certainly
will not change the link_field by doing this, but that's what your
code seems to need to do.

So why not:

rear_ptr->set_link( new_ptr );

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.