Topic: ambiguity


Author: hendrik@vedge.com (Hendrik Boom)
Date: Fri, 10 Sep 1993 20:25:49 GMT
Raw View
What is the correct interpretation.  Compilers differ on this,
so I can't go with the consensus.

class A{
public:
 A(int);
};

class B{
public:
 B(A);
 int k;
};

B c(int d)
{ B e(A(d));
  // Is this a declaration of a B-valued function taking
  // an A-valued parameter?
  // Or is it a declaration of a local B-valued variable
  // which in initialized by callin the constructor
  // B::B(A), whose argument is build by constructing
  // A(d)?
 d = e.k;
  // This is invalid with the  first interpretation
 return e(A(d));
  // This in invalid with the second.

}

--
-------------------------------------------------------
Try one or more of the following addresses to reply.
at work: hendrik@vedge.com,  iros1!vedge!hendrik
at home: uunet!ozrout!topoi!hendrik




Author: pat@tesuji.qc.ca (Patrick Smith)
Date: Sun, 12 Sep 1993 15:04:37 GMT
Raw View
hendrik@vedge.com (Hendrik Boom) writes:
|class A{ ...
|};
|
|class B{ ...
|};
|
|B c(int d)
|{ B e(A(d));
|  // Is this a declaration of a B-valued function taking
|  // an A-valued parameter?
|  // Or is it a declaration of a local B-valued variable
|  // which in initialized by callin the constructor
|  // B::B(A), whose argument is build by constructing
|  // A(d)?

It's a function declaration.  Section 8.1.1 of the ARM gives
this example:

 struct S {
  S(int);
 };

 void foo(double a)
 {
  S x(int(a)); // function declaration
  S y((int)a); // object declaration
  S z = int(a); // object declaration
 }

The principle is "to consider any construct that could possibly
be a declaration a declaration."  This is applied to the sequence
`int(a)' in the ARM's example or `A(d)' in Hendrik's.

--
Patrick Smith
pat@tesuji.qc.ca