P
Peter Bromley
I have been reading about the proposed changes for C++/CLI and they look
great. There is one thing that currently does not work well that I would
like clarified.
A managed C++ property can be assigned or accessed using the get_ and
set_ members, actions which generally work as one would expect
int a = MyIntProp; // calls get_
MyIntProp = 10; // calls set_
But, a natural C++ idiom is chained assignment, something which does not
work with properties as defined now.
int a = MyIntProp = 10; // error C2440: '=' : cannot convert from
'void' to 'double'
MyIntProp = a = 10; // OK
This problems extents to += and other operators (Note that the += itself
is presently coded as a get_ followed by a set_).
a = MyIntProp += 10; // error
The problem here appears to be that the compiler is not creating an
additional get_ call for chained operators, ie as if I wrote:
int a = MyIntProp, MyIntProp = 10; // for first error
or
a = MyIntProp, MyIntProp += 10; // for second error
(Not that I would write code like this normally ;-)
Is anything being done in VS2005 and C++/CLI to conform properties to
this natural C++ programming behaviour? After all, AFAICT what is
required is more compiler smarts - not any changes to C++ or CLI themselves.
Cheers,
Peter
--
If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - (e-mail address removed)
great. There is one thing that currently does not work well that I would
like clarified.
A managed C++ property can be assigned or accessed using the get_ and
set_ members, actions which generally work as one would expect
int a = MyIntProp; // calls get_
MyIntProp = 10; // calls set_
But, a natural C++ idiom is chained assignment, something which does not
work with properties as defined now.
int a = MyIntProp = 10; // error C2440: '=' : cannot convert from
'void' to 'double'
MyIntProp = a = 10; // OK
This problems extents to += and other operators (Note that the += itself
is presently coded as a get_ followed by a set_).
a = MyIntProp += 10; // error
The problem here appears to be that the compiler is not creating an
additional get_ call for chained operators, ie as if I wrote:
int a = MyIntProp, MyIntProp = 10; // for first error
or
a = MyIntProp, MyIntProp += 10; // for second error
(Not that I would write code like this normally ;-)
Is anything being done in VS2005 and C++/CLI to conform properties to
this natural C++ programming behaviour? After all, AFAICT what is
required is more compiler smarts - not any changes to C++ or CLI themselves.
Cheers,
Peter
--
If you wish to reply to me directly, my addres is spam proofed as:
pbromley at adi dot co dot nz
Or if you prefer - (e-mail address removed)