 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Jan Langer Guest
|
Posted: Sun Dec 28, 2003 11:58 pm Post subject: konvertierung der funktionsargumente |
|
|
hallo
ich habe den untenstehenden code und er kompiliert mit der fehlermeldung
no match for `int * A<int>&' operator
unter g++ 3.2.2 nicht. wenn ich allerdings die drei auskommentierten
zeilen benutze geht es wieder.
meine frage ist daher, warum er die konvertierung von int nach A<int>
bei nicht-template-funktionen macht und bei template-funktionen nicht?
gibt es eine loesung? (ausser dem bereitstellen von allen drei
kombinationen von A<T> und T)
jan
-------------------------------------
template <typename T>
struct A {
T value_;
A (A<T> const &a) : value_ (a.value_) {}
A (T v) : value_ (v) {}
};
template <typename T>
A <T> operator * (A <T> const &a1, A <T> const &a2) {
return a1.value_ * a2.value_;
}
//A <int> operator * (A <int> const &a1, A <int> const &a2) {
// return a1.value_ * a2.value_;
//}
int main () {
A <int> a1 (5);
A <int> a2 = 5 * a1;
}
--
jan langer ... [email]jan (AT) langernetz (DOT) de[/email]
"pi ist genau drei"
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|