Überladene pow-funktion
-
also ich möchte die pow-Funktion für verschiedene typen verwenden
(um den Kehrwert zu bilden also ^-1).
für float und double kann man ja die math.h benutzen.
jetzt habe ich noch 2 klassen bruch(mit zähler und nenner) und komplex(mit Real und Imaginärteil).
bei diesen ist der kehrwert ja etwas anders!
also hab ich in den klasse bruch und komplex pow überladen:bruch bruch::pow(const bruch &zahl2, const bruch &a){ bruch erg; erg.zae=zahl2.nen; erg.nen=zahl2.zae; return erg; }will ich diese nun in einer übergeordneten Template klasse (typ2) benutzen
template <typename typ2> matrix<typ2> fkt(const matrix<typ2> &op) { typ2 d=det(op); //det(op) gibt eine variable vom typ typ2 zurück! typ2 a=-1; typ2 kd=pow(d,a); //jetzt soll in kd der kehrwert von d! ... return erg; }bekomme aber diese fehlermeldung:
..\src\matrix.hpp: In function 'matrix<typ2> invers(const matrix<typ2>&) [with typ2 = komplex]':
..\src\matrix.hpp:283: instantiated from 'void DetBerechn(matrix<typ2>) [with typd = komplex]'
..\src\main.cpp:75: instantiated from here
..\src\matrix.hpp:204: error: cannot convert 'komplex' to 'double' for argument '1' to 'double pow(double, double)'
..\src\matrix.hpp: In function 'matrix<typ2> invers(const matrix<typ2>&) [with typ2 = bruch]':
..\src\matrix.hpp:283: instantiated from 'void DetBerechn(matrix<typ2>) [with typd = bruch]'
..\src\main.cpp:76: instantiated from here
..\src\matrix.hpp:204: error: cannot convert 'bruch' to 'double' for argument '1' to 'double pow(double, double)'hört sich für mich an als ob er nicht die überschrieben pow-funktionen benutzt!
jemand ne idee?
-
Dann mach die Funktion "pow" zu einer freien Funktion anstatt einer Memberfunktion (hat dort anscheinend auch nix zu suchen).