F
Fabio Fracassi
Hi,
I belive what i am trying to do is not possible, but I hope someone can
change my mind.
Here is some code i'd like to write:
template <class type> class engine1 {};
template <class type> class engine2 {};
template <template <class> class engine, class type>
class optest : public engine<type> {
public:
optest() : data() {}
optest(const optest& copy) : data(copy.data) {}
type data;
};
template <
template <class> class engine, // This isn't legal
template <class> class engine1,
const optest<engine1, type>& op1,
const optest<engine2, type>& op2) {
optest<engine, type> res;
res.data = op1.data * op2.data;
return res;
}
typedef optest<engine1, int> A1;
typedef optest<engine2, int> A2;
int main() {
A1 a1;
A2 a2;
// I'd like all of the operations below to work.
// These are easy ...
a1 = a1 * a1;
a2 = a2 * a2;
a1 = a1 * a2;
a2 = a2 * a1;
// ... but how can I do this
// without getting ambiguity errors, and ..
a1 = a2 * a1;
a2 = a1 * a2;
// ... how can I do this, at all?
a1 = a2 * a2;
a2 = a1 * a1;
return 0;
}
Is there a way, to do this without conversions. (Becuase these would be
expensive, in the real project).
TIA
Fabio
I belive what i am trying to do is not possible, but I hope someone can
change my mind.
Here is some code i'd like to write:
template <class type> class engine1 {};
template <class type> class engine2 {};
template <template <class> class engine, class type>
class optest : public engine<type> {
public:
optest() : data() {}
optest(const optest& copy) : data(copy.data) {}
type data;
};
template <
template <class> class engine, // This isn't legal
template <class> class engine1,
const optest<engine, type> operator*(template said:
const optest<engine1, type>& op1,
const optest<engine2, type>& op2) {
optest<engine, type> res;
res.data = op1.data * op2.data;
return res;
}
typedef optest<engine1, int> A1;
typedef optest<engine2, int> A2;
int main() {
A1 a1;
A2 a2;
// I'd like all of the operations below to work.
// These are easy ...
a1 = a1 * a1;
a2 = a2 * a2;
a1 = a1 * a2;
a2 = a2 * a1;
// ... but how can I do this
// without getting ambiguity errors, and ..
a1 = a2 * a1;
a2 = a1 * a2;
// ... how can I do this, at all?
a1 = a2 * a2;
a2 = a1 * a1;
return 0;
}
Is there a way, to do this without conversions. (Becuase these would be
expensive, in the real project).
TIA
Fabio