question about returning pointers by reference

I have the class below,

1
2
3
4
5
6
7
8
9
10
11
class List{
    public:
    Node *pstart;
    
    Node *& function(){
        return pstart;
    }   
    
    ...
    
}


and I want to ban the assignation (in black), but at the same time -for speed reasons- I want to keep the return value as a reference.


1
2
3
4
5
6
7
8
9
int main(int argc, char** argv){

    List lista;
    Node *listb=new Node;
    lista.function()=listb;


	return 0;
}


Is there any way I can achieve both requirements?
thanks in advance
santiagorf
Return a Node * const &. That is, a reference to a constant pointer to a Node.
Returning a reference doesn't give you any performance advantage over returning a pointer, by the way.
thank you!!. I was declaring the const before the *
Last edited on
Topic archived. No new replies allowed.