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)
|