octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: color & radio classes


From: Shai Ayal
Subject: Re: color & radio classes
Date: Fri, 1 Jun 2007 22:27:42 +0300

On 6/1/07, John W. Eaton <address@hidden> wrote:
On  1-Jun-2007, Shai Ayal wrote:

| why not define
| color_property& color_property::operator = (const octave_value& val)
|
| and then do
|
| color = val

I think it is generally best to define only one operator= for a class
of the form

  T& operator = (const T&)

and then define constructors for other types:

  T (const U&)
  ...

That allows both

  T t;
  t = U ();

and

  T (U ())

to work.  If you only define specialized operator= functions, you
can't do the latter.

jwe


But in radio_property and color_property we have a situation where the
constructor must also define the set of allowable values -- this is
not inherent to the class as e.g. the set of allowable values of a
"double" class. The solutions I can think of are:
1) define a specialized sub-class for every set of allowable values.
This would allow a constructor taking a single octave_value to do
error checking since it would make the set of allowable values
inherent to the class
2) The situation today where the set of allowable values is required
to be defined at the time of construction and T& operator = (const T&)
is the only = operator defined
3) same as 2 with T& operator = (const octave_value&)

do you have anything else in mind?

Shai


reply via email to

[Prev in Thread] Current Thread [Next in Thread]