NekoSan

I have a function with the purpose of passing an object to it by reference so that you can't edit the object and there's no copy constructor called to save memory, although, what's the purpose of: *const catTwo

Code Snippet

const Cat * const catTwo(const Cat * const theCat)

{

return theCat;

}




Re: Visual C++ General A Pointer Function?

ChopperDavo

Does this even compile

you're not saying what you are trying to do or providing details of how the type Cat is defined.

More info would help.






Re: Visual C++ General A Pointer Function?

NekoSan

The purpose of the function is to teach you to pass an object by reference. I just want to know what the indirection operator and const do to the function -- not the parameters and the return type.

The calling function does this:

Code Snippet

Cat Frisky;

catTwo(&Frisky);






Re: Visual C++ General A Pointer Function?

einaros

The function returns a constant pointer to constant data, that's what the second const is for.

const int* foo; <= pointer to const data

int const * foo; <= also pointer to const data

int * const foo; <= const pointer (cannot be re-assigned) to non-const data

const int * const foo; <= const pointer to const data






Re: Visual C++ General A Pointer Function?

Nishant Sivakumar

This blog entry http://blog.voidnish.com/ p=37 will complement Einaros' excellent reply.




Re: Visual C++ General A Pointer Function?

NekoSan

I see now... I thought the second part was a part of the function somehow and not a part of the return type. I don't know how I came up with that...