Pointer confusion c++ -


i have following practical work complete learn c++, i've been spending long time looking answer , reading through work i'm bit confused clarification of going wrong here. code looks below:

safearray& safearray::operator =(const safearray& other) { //add code here return *this; } 

we have implement code assigns 1 array another. if understand code correctly method takes formal parameter of constant "safearray" called other. & after safearray means actual array passed , not copy while const means can not changed. method returns actual array , not copy of it.

as such thought simple case of creating pointer, referencing memory location of "other" , returning de-referenced result. in attempts code thought i've had no luck.

i tried doing following:

safearray* ptr = &other; //this should have created safearray pointer memory location of array "other". 

the problem here error:

main.cpp:31:23: error: invalid conversion ‘const safearray*’ ‘safearray*’ [-fpermissive] 

i guess reason trying convert i'm not allowed alter can.

i can write code this:

const safearray* = &other; 

but can't return value either. i'm misunderstanding here theoretically presume, please explain missing. i'm more happy work coding out myself can't quite grasp method call.

to correctly define operator, have copy contents of safearray object other passed parameter into this.

the way know how complete function understand contents, ie data members, of safearray class.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -