[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ret: [ns] pointers and addresses




       Hi Jan;
           In my opinion, your aim can be achieved if you get your output from ptr_s() as a parameter -we call it pass-by-reference in computer science- so, you pass the address of the pointer as the parameter to this method like:
int& ptr_s(dyn_rack *out){
  *out = ptr_s_;
  return (1);
   
 }
     Syntax is in C, for I have no idea on syntax used in NS. At least I hope the idea will be useful. Have a nice day:)


> Hi,
> I have created a new header. In this header, I have a field integer num_. I can 
> change its value in my main program with the two lines :
> 
> hdr_rack* cr= (hdr_rack*)p->access(off_rack_);
> cr->num()=value;
> 
> because, in my header, I have defined the function num() like this :
> 
> int& num() {return num_;}
> 
> But now, I would like to do the same with a pointer ptr_s_ to a structure.
> 
> I tried this : 
> 
> dyn_rack *ptr_s_;
> dyn_rack* ptr_s() {return ptr_s_;} 
> 
> but when I try to change the value of this pointer in my main program, I have an 
> error :
> non-lvalue in assignment
> 
> So could anybody show me  the line to type to define the correct function in my 
> header so I could change the value of the pointer ( ex.: so I could have the 
> equivalency of ptr_s=malloc ... but with the function defined in my header as 
> with num(), I want num=5, I write cr->num()=5 ).
> 
> Thank you.
>    Jan.
> 
> 



Yakup Balka�
Bilgisayar M�hendisi
Bilkent �niversitesi Elektrik-Elektronik M�h