3 Replies - 220 Views - Last Post: 10 November 2012 - 06:21 AM Rate Topic: -----

#1 MrOutsider  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 06-March 12

Confusing node pointer assignement error.

Posted 09 November 2012 - 01:25 PM

First of all. I appreciate the help guys!


This is the problem.Trying to set one of list's edges to null[/b]
list[i].getAttachedNode(j) = 0;


This is the error.

[i]Prj3.cpp:165:34: error: lvalue required as left operand of assignment


This is my list decleration.
Node list[47];


This is the attachedNode implementation.

Node* Node::getAttachedNode(int direction) {return attachedNode[direction];}





[b]Here is the block its contained in.

	for(int i = 0; i<48; i++)
	{
		for(int j = 0; j<6; j++)
		{	
		string info = g.returnInfo(i,j);
		
			switch(j)
				{
			case 0:
			list[i].setNodeName(info);
			break;
			case 1:
			if(info.compare(null) == 0)
			{list[i].getAttachedNode(j) = 0;}
			break;
				}
		}
	}


Is This A Good Question/Topic? 0
  • +

Replies To: Confusing node pointer assignement error.

#2 mojo666  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 352
  • View blog
  • Posts: 770
  • Joined: 27-June 09

Re: Confusing node pointer assignement error.

Posted 09 November 2012 - 01:53 PM

This is not valid syntax.
list[i].getAttachedNode(j) = 0;


I am not exactly sure what is being set to 0, but you need to make a method in node to set a member variable. Once the method is made, the call should looks something like

list[i].getAttachedNode(j).setValue(0);
//or
list[i].setAttachedNode(j, 0);


Was This Post Helpful? 0
  • +
  • -

#3 MrOutsider  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 06-March 12

Re: Confusing node pointer assignement error.

Posted 09 November 2012 - 02:09 PM

list is an array of node objects. Im grabbing the objects pointers with getAttachedNode() then trying to set it to null or 0 as in c++. Im not just trying to set a member variable to 0.

I can tell its not valid syntax, but all the others ive tried failed too. Im confused on how to set this pointer to null.

Each node class contains
Node *attachedNode[4];

This post has been edited by MrOutsider: 09 November 2012 - 02:13 PM

Was This Post Helpful? 0
  • +
  • -

#4 Xupicor  Icon User is offline

  • Nasal Demon
  • member icon

Reputation: 249
  • View blog
  • Posts: 582
  • Joined: 31-May 11

Re: Confusing node pointer assignement error.

Posted 10 November 2012 - 06:21 AM

@mojo666 it's not so simple, see - the syntax itself is valid. The usage is wrong.

It's the pointer that gets returned from the member function that gets set to 0. That however really accomplishes nothing, since that pointer is a value that gets discarded afterwards, and that changes nothing inside the node object.

You actually could write something that would look like that code, and work, but I wouldn't recommend it, it would be too confusing. (not the implementation itself, the usage)

First, without seeing more code I won't be able to help much, I'm afraid. It doesn't look like a linked list much, so what is it?
Also, MrOutsider, if you store pointers, I suspect you new your objects then? When you set them to NULL here, do you not want to delete them first?

And this:
if(info.compare(null) == 0)
What is this? What is "null" here?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1