Click here to Skip to main content
12,244,322 members (52,502 online)

C / C++ / MFC

 
AnswerRe: User privileges stopping a program from rename(,)'ing files Pin
Super Lloyd20-Jan-13 20:52
memberSuper Lloyd20-Jan-13 20:52 
GeneralBUG FOUND Pin
Anthony Appleyard21-Jan-13 1:03
memberAnthony Appleyard21-Jan-13 1:03 
GeneralRe: BUG FOUND Pin
Super Lloyd21-Jan-13 1:57
memberSuper Lloyd21-Jan-13 1:57 
QuestionA pointer reference as l-value Pin
George Nistor20-Jan-13 3:07
memberGeorge Nistor20-Jan-13 3:07 
hi
Here is my problem:
I don't understand why in the following code the second line is error and the third is ok.
In the first case where the error is I will get a copy and in the second reference to the pointer.
Why the reference is considered l-value?

// Node class
class Node {
private:
	int key;
	Node* left;
	Node* right;
 
	typedef Node* Link;
public:
	Node() { key=-1; left=NULL; right=NULL;};
	void setKey(int aKey) { key = aKey; };
	int Key() { return key; };
	Link Left() { return left; };
	Link& Right() { return right; };
};
 
int _tmain(int argc, _TCHAR* argv[])
{
	Node *p= new Node();
	p->Left()= new Node(); //error : error C2106: '=' : left operand must be l-value
	
	p->Right()= new Node(); //this one is lvalue
	
	return 0;
}


modified 20-Jan-13 8:56am.

AnswerRe: A pointer reference as l-value Pin
Maximilien20-Jan-13 4:18
memberMaximilien20-Jan-13 4:18 
AnswerRe: A pointer reference as l-value Pin
Richard MacCutchan20-Jan-13 4:56
mvpRichard MacCutchan20-Jan-13 4:56 
GeneralRe: A pointer reference as l-value Pin
George Nistor20-Jan-13 5:02
memberGeorge Nistor20-Jan-13 5:02 
GeneralRe: A pointer reference as l-value Pin
Richard MacCutchan20-Jan-13 5:11
mvpRichard MacCutchan20-Jan-13 5:11 
GeneralRe: A pointer reference as l-value Pin
Freak3021-Jan-13 5:43
memberFreak3021-Jan-13 5:43 
GeneralRe: A pointer reference as l-value Pin
George Nistor21-Jan-13 6:37
memberGeorge Nistor21-Jan-13 6:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 1 May 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid