Topic: implied/implicit object paramter/argument


Author: litb <Schaub-Johannes@web.de>
Date: Mon, 5 Jan 2009 02:21:36 CST
Raw View
Hello all,

I'm having difficulties to understand the difference between these
four various terms:

* implied object argument
* implied object parameter
* implicit object argument
* implicit object parameter

As i've understood it (until today), for the purpose of overload
resolution, there is a hidden parameter for each member function, and
a hidden argument for each call to a member function involved:

   struct A { void f() const; void f(); };

The parameter which is called *implicit object parameter* is a hidden
first parameter that is A& for nonconst and A const& for const member
functions. That's what i read about in the C++ Standard, 1998 chapter
13.3.1.

   A a; a.f();

Here, the hidden first parameter will receive a hidden first argument,
which is called *implied object argument* and represents the object
that the function was called on. It denotes the object that the
function was called on. (Also in 13.3.1). In checking which candidate
member function's implicit object parameter binds better to the
implied object argument (i.e which standard conversion sequence is
better) overload resolution can choose the better function to call
regarding the object denoted by *this.

So far so good. But now, i read in the Standard about an *implicit
object argument* and *implied object parameter*, which seem to have
swapped their meaning. For example, in this sentence:

"For conversion functions, the function is considered to be a member
of the class of
the implicit object argument for the purpose of defining the type of
the implicit object parameter." in 13.3.1, p4.

I don't understand that sentence at all. But what worries me at most,
what the heck is *implicit object argument* ?? The other text is:

"The selection criteria for the best function are the number of
arguments, how well the arguments
match the types of the parameters of the candidate function, how well
(for nonstatic member functions) the object matches the implied object
parameter, and certain other properties of the candidate function."

What the heck does *implied object parameter* mean? Isn't it a implied
object argument, like in the other cases?

Summary:

What is the difference between those 4 terms? I don't think it's just
because the Standard doesn't care. But i think i don't just get
something very important. Thanks for any help in advance!

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Jiang <goo.mail01@yahoo.com>
Date: Wed, 7 Jan 2009 10:27:43 CST
Raw View
On Jan 5, 5:21 pm, litb <Schaub-Johan...@web.de> wrote:


> I'm having difficulties to understand the difference between these
> four various terms:
>
> * implied object argument
> * implied object parameter
> * implicit object argument
> * implicit object parameter
>

[...]

> What the heck does *implied object parameter* mean? Isn't it a implied
> object argument, like in the other cases?
>
> Summary:
>
> What is the difference between those 4 terms? I don't think it's just
> because the Standard doesn't care. But i think i don't just get
> something very important. Thanks for any help in advance!
>

To understand the differences, it is better first get the meanings of
"argument" and "parameter".

In 1.3.1, we have

1.3.1 [defns.argument]
argument
an expression in the comma-separated list bounded by the
parentheses in a function call expression; a sequence of
preprocessing tokens in the comma-separated list bounded
by the parentheses in a function-like macro invocation;
the operand of throw; or an expression, type-id or
template-name in the comma-separated list bounded by
the angle brackets in a template instantiation.
Also known as an actual argument or actual parameter.

and in 1.3.10 [defns.parameter]
parameter
an object or reference declared as part of a function
declaration or definition, or in the catch Clause of an
exception handler, that acquires a value on entry to
the function or handler; an identifier from the comma-
separated list bounded by the parentheses immediately
following the macro name in a function-like macro definition;
or a template-parameter.
Parameters are also known as formal arguments or
formal parameters.

So, for example, in the following function definition,

   void foo(int a, int b){}

"a", "b" are parameters, and in the following function
call,

   void bar(){
      int i,j;
      // ...
      foo(i, j);
   }

, "i" and "j" are both arguments. For the binding,
compiler will do necessary initialization or
conversion during function call. While parsing
the standard, you can always replace "parameter"
with "formal argument" without any problem
in my mind.

And the get the full set of candidate functions for
overload resolution, the standard allows
implementations use "implicit object parameter"
and "implied object argument" to make the
resolution process easier, though these arguments
are usually invisible from the view points of
programmers.

In 13.3.1/p2, we have
[...]
a member function is considered to have an extra
parameter, called the implicit object parameter, which
represents the object for which the member function
has been called.

and in 13.3.1/p3,
[...]
when appropriate, the context can construct an
argument list that contains an implied object argument
to denote the object to be operated on.

Again, an example:

struct A
{
   void foo(int i) {}
   // think it as : A_foo(A& obj, int i)

   void foo(int i) const {}
   // think it as : A_foo(A& const obj, int i)
};

int main()
{
   A a;

   // cv-unqualified object, call normal member
   // think it as: A_foo(A&obj = a, int i = 1)
   a.foo(1);

   const A const_a = a;

   // cv-qualified object, call const member
   // think it as: A_foo(A& const obj = const_a, int i = 2)
   const_a.foo(2);

}

HTH,

Jiang


--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: litb <Schaub-Johannes@web.de>
Date: Wed, 7 Jan 2009 12:17:41 CST
Raw View
On 7 Jan., 17:27, Jiang <goo.mai...@yahoo.com> wrote:
[...]

Thanks for your detailed answer. I understand the difference between
the terms "argument" and "parameter", and your answer made me believe
i'm right in what i thought they are. I also know what implied object
argument are the object that the call is made on at the call side, and
that implicit object parameter is the object that that object has in
the body of the function of all candidates. But how do the other
terms, implicit object argument and implied object parameter happen to
relate to that? Is it like this:

   implicit object argument <=> implied object argument
   implied object parameter <=> implicit object parameter

So that we actually have to do with only two things, but 4 terms? But
if that is the case, why does the Standard do that? Is there some
rationale for that?

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]