Erik Wikström <Erik-> wrote:
: On 2007-11-18 16:57, Thelma Roslyn Lubkin wrote:
:> Erik Wikström <Erik-> wrote:
:> : On 2007-11-18 15:07, Thelma Roslyn Lubkin wrote:
:> :> Is there any way for me to overload that 'scalar(0)' so that it's
:> :> defined for the myclass elements of amatrix?
:>
:> : If you have the template type something like this:
:>
:> : template<class T>
:> : class matrix
:> : {
:> : // ...
:> : };
:>
:> : Then you can use T() to get the default value for whatever T is, so
:> : replace "mx[i][j] = scalar(0);" with "mx[i][j] = T();" <snip>
:> This means that I can't use the matrix(rowLen,colLen)
:> constructor if the matrix elements are such objects, because
:> mx[i][j] = T() wouldn't work for matrix elements that are
:> simple scalars like double -- so I'll need to provide a separate
:> constructor for elements that are objects?
: Actually, that is the beauty of it: it works for the built-in types too
: and will set their value to 0 (I think for all of them) as demonstrated
: by this simple code:
Thank you: that worked for me, for both integers and for my
objects. It truly is beautiful.
--thelma
: --
: Erik Wikström
|