Thread View: borland.public.cppbuilder.oodesign
3 messages
3 total messages
Started by Shannon Peterson
Wed, 16 Mar 2005 15:51
Meaning
Author: Shannon Peterson
Date: Wed, 16 Mar 2005 15:51
Date: Wed, 16 Mar 2005 15:51
14 lines
1329 bytes
1329 bytes
I have a chunck of code and it uses code like: AnsiString mystring = ::func(stuff() + "string"); all over the place and I was wondering if the :: is just allocating space for data returned by the function call? is it the same as void::Func()? if my assumption is wrong could you please correct me. thanks Shannon
Re: Meaning
Author: Thomas Maeder [TeamB]
Date: Wed, 16 Mar 2005 16:08
Date: Wed, 16 Mar 2005 16:08
44 lines
2321 bytes
2321 bytes
Shannon Peterson <speterson@ae-solutions.com> writes:
> AnsiString mystring = ::func(stuff() + "string");
>
> all over the place and I was wondering if the :: is just allocating
> space for data returned by the function call?
Not at all.
The expression
func("string")
means that a function named func() is to be called, and "string" is to
be passed as argument.
This sounds simple, but it's not. Because in C++, we have
overloading.
The compiler thus first has to look for functions named func in a
sequence of namespaces. As soon as one or more functions named func
have been found in a namespace, this search stops. Among the functions
found, those that can't take "string" as an argument are discarded
from the candidate functions. If this process ends up with exactly one
function, that function is called.
Prefixing func with :: changes the sequence of namespace where the
search for func is performed: func() is only looked for the global
namespace.
> is it the same as void::Func()?
No.
void::Func()
is a sytax error, while
AnsiString mystring = ::func(stuff() + "string");
is syntactically correct.
Re: Meaning
Author: Shannon Peterson
Date: Wed, 16 Mar 2005 16:17
Date: Wed, 16 Mar 2005 16:17
54 lines
2437 bytes
2437 bytes
Thanks, it all makes sense now.
Shannon
Thomas Maeder [TeamB] wrote:
> Shannon Peterson <speterson@ae-solutions.com> writes:
>
>
>>AnsiString mystring = ::func(stuff() + "string");
>>
>>all over the place and I was wondering if the :: is just allocating
>>space for data returned by the function call?
>
>
> Not at all.
>
>
> The expression
>
> func("string")
>
> means that a function named func() is to be called, and "string" is to
> be passed as argument.
>
>
> This sounds simple, but it's not. Because in C++, we have
> overloading.
>
> The compiler thus first has to look for functions named func in a
> sequence of namespaces. As soon as one or more functions named func
> have been found in a namespace, this search stops. Among the functions
> found, those that can't take "string" as an argument are discarded
> from the candidate functions. If this process ends up with exactly one
> function, that function is called.
>
> Prefixing func with :: changes the sequence of namespace where the
> search for func is performed: func() is only looked for the global
> namespace.
>
>
>
>>is it the same as void::Func()?
>
>
> No.
>
> void::Func()
>
> is a sytax error, while
>
> AnsiString mystring = ::func(stuff() + "string");
>
> is syntactically correct.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads