473,387 Members | 3,820 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.

Linked-List help

<snippet>

class Node1
{
Node2* link;

public:
void insertNode2(Node2* innerNode)
{
link->getNext() = innerNode; //***error -- non-lvalue in
assignment
}
};

class Node2
{
Node2* next;

public:
Node2* getNext(){ return next;}
};

---

Why Am I getting an error denoted at ***?
wewewewe

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 15/08/2003
Jul 19 '05 #1
6 2513
Ying Yang wrote:
<snippet>

class Node1
{
Node2* link;

public:
void insertNode2(Node2* innerNode)
{
link->getNext() = innerNode; //***error -- non-lvalue in
assignment
}
};

class Node2
{
Node2* next;

public:
Node2* getNext(){ return next;}
};

---

Why Am I getting an error denoted at ***?


Because you try to assign a new value to an unnamed temporary variable.

--
WW aka Attila
Jul 19 '05 #2
White Wolf wrote:
[SNIP]
link->getNext() = innerNode; //***error -- non-lvalue in [SNIP] Node2* getNext(){ return next;}

Why Am I getting an error denoted at ***?


Because you try to assign a new value to an unnamed temporary
variable.


What is returned by getNext is a copy of what is stored in next, it is an
unnamed copy: the return value. You will need to return a reference to that
pointer to be able to assign to it.

--
WW aka Attila
Jul 19 '05 #3
Ying Yang wrote:
<snippet>

class Node1
{
Node2* link;

public:
void insertNode2(Node2* innerNode)
{
link->getNext() = innerNode; //***error -- non-lvalue in
assignment
}
};

class Node2
{
Node2* next;

public:
Node2* getNext(){ return next;}
};

---

Why Am I getting an error denoted at ***?


The method Node2::getNext returns a _copy_ of a pointer Node2::next.
In Node1::insertNode2, you are assigning innerNode to the copy
of a pointer (returned by Node2::getNext).

The above code suggests that you are having problems with a
linked list or tree data structure. Why are you using two Nodes?
If you post a description of the bigger picture, we may be
able to give better help, such as:

For trees requiring inner and leaf nodes:
1. Create a parent class containing common methods and
members for nodes.
2. Have leaf and inner nodes inherit from the parent.
3. Let the tree be represented by pointers to the
parent node.
4. All pointers are pointers to the parent class.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 19 '05 #4
> [SNIP]
link->getNext() = innerNode; //***error -- non-lvalue in [SNIP] Node2* getNext(){ return next;}

Why Am I getting an error denoted at ***?
Because you try to assign a new value to an unnamed temporary
variable.


What is returned by getNext is a copy of what is stored in next, it is an
unnamed copy: the return value.


Right, you mean the memory address of what next is pointing to? even though
the return type says it should return a pointer of type Node2?
You will need to return a reference to that
pointer to be able to assign to it.


How about:

Node2* temp = link->getNext();
temp = innerNode;

or how do I make getNext() return a pointer of type Node2?
Node2* getNext()
{
...
}


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.510 / Virus Database: 307 - Release Date: 14/08/2003
Jul 19 '05 #5


Ying Yang wrote:
[SNIP]
> link->getNext() = innerNode; //***error -- non-lvalue in [SNIP]
> Node2* getNext(){ return next;}
>
> Why Am I getting an error denoted at ***?

Because you try to assign a new value to an unnamed temporary
variable.


What is returned by getNext is a copy of what is stored in next, it is an
unnamed copy: the return value.


Right, you mean the memory address of what next is pointing to? even though
the return type says it should return a pointer of type Node2?


Right. And a pointer to Node2 is just that: a number.
You can't assign something to a number.
You will need to return a reference to that
pointer to be able to assign to it.
How about:

Node2* temp = link->getNext();


temp now points to whatever getNext() also points ..
temp = innerNode;
.... and now temp points to innerNode.

But the thing in getNext() still points to the same thing.

or how do I make getNext() return a pointer of type Node2?


That's not what you want to do. You don't want to return a
pointer to Node2, for the simple fact that this would be useless
for the caller if he wants to assign a new address.
The solution has already been shown to you: return a reference
to a pointer. Didn't you see it?

Node2*& getNext()
{
...
}

Since you don't seem to be very knowledged in pointers, pointers to pointers
and/or references, let me suggest something different.
In addition to having such a GetNext function, why don't you simply
add a SetNext function to your class:

class Node2
{
Node2* next;

public:
Node2* getNext() { return next;}
void setNext( Node2* n ) { next = n; }
};

class Node1
{
Node2* link;

public:
void insertNode2(Node2* innerNode)
{
link->setNext( innerNode );
}
};

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 19 '05 #6
"Ying Yang" <Yi******@hotmail.com> wrote in message news:<3f********@news.iprimus.com.au>...
<snippet>

class Node1
{
Node2* link;

public:
void insertNode2(Node2* innerNode)
{
link->getNext() = innerNode; //***error -- non-lvalue in
assignment
}
};

class Node2
{
Node2* next;

public:
Node2* getNext(){ return next;}
};


The reason for this error was already explained by previous posters.
To make your code work, I would suggest to add a declaration

friend class Node1;

into class Node2 (change the order in which the class appear to make
this legal) and change the function into:

void insertNode2(Node2* innerNode)
{ link->next=innerNode;
}

Reason: You probably do not want a public method to return a reference
to a private value because then it is not terribly private anymore.
Furthermore, you might want to change the name Node2 into Node and
Node1 into LinkedList.

Good day,
Chris Dams
Jul 19 '05 #7

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

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
2
by: Robert McGregor | last post by:
Hi all, I've got a Front End / Back End database that was working just fine. One day i opened the FE to find that if I tried to open one of the linked tables from the database window, nothing...
3
by: Michael Plant | last post by:
Hello one and all. I have a stored table in my database and the form I'm using is based on a query that draws data from my stored table and a linked table. The linked table is a *.txt file. ...
4
by: Neil Ginsberg | last post by:
I have ODBC linked tables to a SQL 7 database in an A2K database. The linked tables do not have the password stored in them, so the first time the user accesses them, they need to enter the SQL...
1
by: Phil Abrahamsen | last post by:
Access 2002: Example: Master record: ID#, Name Linked records: ID#, Member year If a member for the last 3 years you have 3 linked records withmember year = 2002, 2003, and 2004. I want to...
3
by: Zlatko Matić | last post by:
Hi! What happens with linked tables if they were linked using File DSN, when I copy the Access file on some other PC without File DSN ? What is the difference between DSN on linked tables and...
6
by: Neil | last post by:
After creating a linked server to a remote server, I needed to log in using sp_addlinkedsrvlogin to get my stored procedure to work. However, I noticed that after stopping SQL Server and the DTC...
5
by: Neil | last post by:
I am getting time-out errors when I try to perform a simple delete on a linked server. The command is: Delete From MyTable Where PKID=12345 I have tried executing this command directly from...
9
by: erick-flores | last post by:
If you have access to the database that the linked table is in, modify it there. You can't modify a linked table. Alternatively, you can import the linked table, then it won't be linked any more...
25
by: bubbles | last post by:
Using Access 2003 front-end, with SQL Server 2005 backend. I need to make the front-end application automatically refresh the linked SQL Server tables. New tables will be added dynamically in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.