TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: THOMAS MAEDER
from: ALBERTO MONTEIRO
date: 1997-12-26 10:44:00
subject: What`s wrong with this?

AM> template  class Finite_Dimensional_Field
AM> public:
AM>   Field v[dimension];
AM> // here force Field to have operator+(Field &, Field &) and ...
AM> // operator*(Field &, Field &) and some other math stuff
AM> };
TM>Yes. Just use these operators. The compiler will refuse to instantiate
TM>the template for a Field type that doesn't offer them.
I tried to create this "Module" [the weaker mathematical concept,
equivalent to a Vector space over a Ring], below, but I guess I have to
put more information to it :-(
template  class Module {
public:
   Ring v[dimension];
   Module();
   Module operator+(const Module m2) const;
   friend Module operator*(Ring x, const Module m2);
};
Module::Module()        // here the compiler say it's wrong
{
        for (int i = 0; i < dimension; i++)
                v[i] = 0;
}
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;
}
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;
}
Alberto Monteiro
---
 þ SLMR 2.1a þ Do, or do not.  There is no "try". (Yoda)
--- 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™.