fehler: methode [with T = int] cannot be overloaded
-
hmm ja also ich bin grad dabei ein paar templateklassen zu schreiben. bis jetzt hat auch alles funktioniert. leider sagt er mir jetzt "methode [with T = int] cannot be overloaded"
//entity.h #ifndef _ENTITY_H #define _ENTITY_H #include "vector.h" namespace VR { template <class T> class Entity { public: Entity(T intiX, T initY, T initXSpeed, T initYSpeed); Entity(Vector<T> initPosition, Vector<T> initSpeed); ~Entity(); void accelerate(Vector<T> acc); void step(); const Vector<T> getPosition(); const Vector<T> getSpeed(); private: Entity(); void accelerate(Vector<T> acc); void step(); Vector<T> position, speed; }; template <class T> Entity<T>::Entity() { } template <class T> Entity<T>::Entity(T initX, T initY, T initXSpeed, T initYSpeed) :position(Vector<T>(initX, initY)), speed(Vector<T>(initXSpeed, initYSpeed)) { } template <class T> Entity<T>::Entity(Vector<T> initPosition, Vector<T> initSpeed) :position(initPosition), speed(initSpeed) { } template <class T> Entity<T>::~Entity() { } template <class T> void Entity<T>::accelerate(Vector<T> acc) //hier meckert er (fehler genauer weiter unten) { speed += acc; } template <class T> void Entity<T>::step() //und hier meckert er (fehler genauer weiter unten) { position += speed; } template <class T> const Vector<T> Entity<T>::getPosition() { return position; } template <class T> const Vector<T> Entity<T>::getSpeed() { return speed; } }//vector.h #ifndef _VECTOR_H #define _VECTOR_H #include "coordinate.h" namespace VR { template <class T> class Vector : public Coordinate<T> { public: Vector(); Vector(T initX, T initY); ~Vector(); void operator+=(Coordinate<T> aCoordinate); void addX(T aX); void addY(T aY); void add(T aX, T aY); }; template <class T> Vector<T> ::Vector() { } template <class T> Vector<T>::Vector(T initX, T initY) { Coordinate<T>::x = initX; Coordinate<T>::y = initY; } template <class T> Vector<T>::~Vector() { } template <class T> void Vector<T>::operator+=(Coordinate<T> aCoordinate) { Coordinate<T>::x += aCoordinate[0]; Coordinate<T>::y += aCoordinate[1]; } template <class T> void Vector<T>::addX(T aX) { setX(Coordinate<T>::getX() + aX); } template <class T> void Vector<T>::addY(T aY) { setY(Coordinate<T>::getY() + aY); } template <class T> void Vector<T>::add(T aX, T aY) { addX(aX); addY(aY); } } #endif//coordinate.h #ifndef _COORDINATE_H #define _COORDINATE_H #include <stdexcept> #include <iostream> namespace VR { template <class T> class Coordinate { public: Coordinate(); Coordinate(T initX, T initY); ~Coordinate(); T& operator[](int index); protected: T x, y; }; template <class T> Coordinate<T>::Coordinate() { } template <class T> Coordinate<T>::Coordinate(T initX, T initY) :x(initX), y(initY) { } template <class T> Coordinate<T>::~Coordinate() { } template <class T> T& Coordinate<T>::operator[](int index) { if (index == 0) return x; if (index == 1) return y; else throw "out of range in a Coordinate or a erived class"; } } #endif//main.cc #include <iostream> #include "../include/entity.h" #include "../include/vector.h" #include "../include/fair_container.h" int main() { VR::Entity<float> a(1,2,3, 4), b(5,6,7,8); std::cout << a.getPosition()[0] << ' ' << a.getPosition()[1] << std::endl; return 0; }Fehler:
../include/entity.h:62: error: ‘void VR::Entity<T>::accelerate(VR::Vector<T>) [with T = int]’ cannot be overloaded ../include/entity.h:25: error: with ‘void VR::Entity<T>::accelerate(VR::Vector<T>) [with T = int]’ ../include/entity.h:68: error: ‘void VR::Entity<T>::step() [with T = int]’ cannot be overloaded ../include/entity.h:26: error: with ‘void VR::Entity<T>::step() [with T = int]’wenn ich einfach zwei int-vectoren anlegen und dies mit += addiere funktionier t alles:
#include <iostream> #include "../include/entity.h" #include "../include/vector.h" #include "../include/fair_container.h" int main() { VR::Vector<int> a(1,2), b(3,4); a += b; std::cout << a[0] << ' ' << a[1] << std::endl; return 0; }Ausgabe damit:
EXECUTING: /home/mambokurt/Projects/VectorRace/src/vectorrace ---------------------------------------------- 4 6 ---------------------------------------------- Program exited successfully with errcode (0) Press the Enter key to close this terminal ...was bedeutet das? wie bekomme ich das geregelt?
[Edit]
das scheint also irgendwie an den namen zu liegen.
wenn ich die beiden methoden umbenenne - zB in kop und musch - dann kompiliert er ohne probleme.
wenn ich jetzt noch wüsste, warum er step() und accelerate() als namen nicht annimmet, dann wäre ich ein glücklicher mann.
[/Edit]mfG MamboKurt
-
hast sich erledigt.
ich war so blöd und hab übersehen, dass ich in der klasse die methoden zweimal eingetragen hatte. einmal unter public einaml unter private.