[comp.sys.mac.programmer] Pointers to sibling classes in conditional expressions

robertk@lotatg.lotus.com (Robert Krajewski) (04/25/91)

I have a function that returns a pointer to a parent class -- it looks
at its arguments, and then makes a new object (with new) either of
child class A, or B, depending on the arguments to this function. The
decision is made in a conditional expression, and the result is
returned:

Parent * MakeIt(...)
{	
	...
	return ( <cond> ? new A(...) : new B(...) );
}

g++ warns that the two expressions are of different types, and so does
MPW C++.

However, it seems to me that I shouldn't get a warning. (MPW C++
actually considers this an error.) Return value conversion ought to be
following the same rules as conversion of class pointer types. This
code should not produce warnings:

F(Parent * thing);

F(new A(...));
F(new B(...));

... and I would argue that something analogous is happening in the
conditional expression example above.

Is there anything in the ARM to contradict what I'm saying ? If so, do
I have a reasonable complaint that should be addressed in the
standards effort ?