AM> template class Module {
AM> public:
AM> Ring v[dimension];
AM> Module();
AM> Module operator+(const Module m2) const;
AM> friend Module operator*(Ring x, const Module m2);
AM> };
AM> Module::Module() // here the compiler say it's wrong
You have to write
template
Module::Module()
AM> Module Module::operator+(const Module m2) const
AM> {
AM> Module rval;
AM> for (int i = 0; i < dimension; i++)
AM> rval.v[i] = v[i] + m2.v[i];
AM> return rval;
AM> }
To have the module instances look more like built-in types, you might
also define an operator+= and implement operator+ in terms of
operator+=.
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> }
This operator is not symmetrical. You might also define
template
Module
Module::operator*(const Module &m, Ring x)
and implement both of them in terms of an operator*=.
Note that I pass the module by reference which is usually more
efficient.
Thomas
---
þ MM 1.0 þ Unregistered þ MailMaker - Your Windows offline reader!
---------------
* Origin: McMeier & Son BBS (2:301/138)
|