all groups > visual studio .net general > july 2004 >
You're in the

visual studio .net general

group:

Should this compile?


Should this compile? Developer
7/28/2004 9:35:57 PM
visual studio .net general:
Hello,

Don't know if this is the right group, but I didn't see a more appropriate
one.

class simple {
int i;
long l;
};
void func(const simple * & ps) {
Console::WriteLine(S"Hello World from the land of func");
}
int _tmain()
{
Console::WriteLine(S"Hello World");
simple * pSimple = new simple();
func(pSimple);

return 0;
}

Does the function signature of func() _require_ that its argument be a const
pointer, or does the signature determine what the function can do with the
pointer?
This snippet compiles on VS.Net 2003.


TIA.

RE: Should this compile? v-garych NO[at]SPAM online.microsoft.com (
7/29/2004 7:27:02 AM
Hi,

[quoted text, click to view]
const pointer,
No, it needn't.

[quoted text, click to view]
Yes, the object which the pointer referenced cannot be modified within the
func(), however the pointer itself can be reassigned:

e.g.
class simple {
int i;
long l;
public:
int tmp;
};
void func(const simple* &ps) {
Console::WriteLine(S"Hello World from the land of func");
ps->tmp = 2; // error!
ps = NULL; // OK
}


By the way, it is better to post such C++ issue in the
microsoft.public.vc.lanuage


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Re: Should this compile? Developer
8/2/2004 10:53:44 AM
Thanks, Gary, that answers my question.

[quoted text, click to view]

Re: Should this compile? v-garych NO[at]SPAM online.microsoft.com (
8/3/2004 1:29:55 AM
Hi,

We are glad to help you on this problem, have a nice day!


Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
AddThis Social Bookmark Button