TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS MAEDER
from: ALBERTO MONTEIRO
date: 1998-01-06 00:19:00
subject: What`s wrong with this?

TM>You have to write
TM>template 
TM>Module::Module()
This worked right
TM>To have the module instances look more like built-in types, you  might
TM>also  define  an  operator+=  and  implement  operator+  in  terms  of
TM>operator+=.
I know that; I just wanted to make a skeleton template
AM> Module operator*(Ring x, const Module m2)
AM> {
AM>         Module rval;
AM>         for (int i = 0; i < dimension; i++)
AM>                 rval.v[i] = x * m2.v[i];
AM>         return rval;
AM> }
TM>This operator is not symmetrical. You might also define
It shouldn't be; it's usual to define x * v for x a scalar and v a
vector, but not v * x.
TM>Note that I pass  the  module  by  reference  which  is  usually  more
TM>efficient.
Ok. But now there's also an other problem:
template 
class Module {
public:
        Ring v[dimension];
        Module();
        Module operator+(const Module & m2) const;
        friend Module operator*(Ring x, const Module & m2);
};
template 
Module::Module()
{
        for (int i = 0; i < dimension; i++)
                v[i] = 0;
}
template 
Module
Module::operator+(const Module & m2) const
{
        Module rval;
        for (int i = 0; i < dimension; i++)
                rval.v[i] = v[i] + m2.v[i];
        return rval;
}
template     // compiler says this is wrong :-(
Module operator*(Ring x, const Module & m2)
{
        Module rval;
        for (int i = 0; i < dimension; i++)
                rval.v[i] = x * m2.v[i];
        return rval;
}
---
 þ SLMR 2.1a þ Dream the same thing every night (Metallica)
--- FMail/386 1.02
---------------
* Origin: CentroIn! +55-21-205-0281, 41 lines, 24h, RJ/Brazil (4:802/21)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.