Hallo,
heute habe ich wieder Lust gehabt C++ zu lernen, deshalb verzeiht mir bitte wenn die Frage dämlich ist
Ich habe angefangen mit der SFML ein kleines Spiel zu programmieren und soweit funktioniert auch alles. Weil die Vektoren von der SFML aber keine Hilfsfunktionen haben, wollte ich mir einen kleinen math-namespace schreiben, bei dem ich aber jetzt hängen geblieben bin, denn anscheinend erkennt der Compiler nicht die Typen der Parameter (VC++)
Folgender Fehler tritt zweimal auf:
|
Quellcode
|
1
2
|
1>c:\users\admin\documents\visual studio 2010\projects\sfml-dev\sfml-dev\math.cpp(8): error C2664: 'math::clamp': Konvertierung des Parameters 1 von 'float' in 'const sf::Vector2f &' nicht möglich
1> Ursache: Konvertierung von 'float' in 'const sf::Vector2f' nicht möglich
|
Meine
Math.hpp:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
|
#pragma once
#include <SFML\System.hpp>
namespace math
{
static sf::Vector2f clamp(const sf::Vector2f& min, const sf::Vector2f& max, const sf::Vector2f& x);
static float clamp(const float& min, const float& max, const float& x);
}
|
Und das sind die beiden Funktionen:
|
C-/C++-Quelltext
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include <SFML\System.hpp>
namespace math
{
static inline sf::Vector2f clamp(const sf::Vector2f& min, const sf::Vector2f& max, const sf::Vector2f& x)
{
return sf::Vector2f(math::clamp(min.x, max.x, x.x), math::clamp(min.y, max.y, x.y));
}
static inline float clamp(const float& min, const float& max, const float& x)
{
return (x < min ? min : (x > max ? max : x));
}
}
|
In Zeile 7 habe ich auch versucht, die Typen explizit anzugeben, doch der Fehler bleibt der selbe:
|
C-/C++-Quelltext
|
1
|
return sf::Vector2f(math::clamp((float)min.x, (float)max.x, (float)x.x), math::clamp((float)min.y, (float)max.y, (float)x.y));
|
Man könnte die Funktionen natürlich umbenennen (à la
clampVector), aber mich würde es interessieren, wieso das jetzt nicht funktioniert. Gegoogelt habe ich nach dem Fehler natürlich auch schon, doch dort sind die Probleme für mich offensichtlicher und hier sind das auch unterschiedliche Typen... Ich programmiere jetzt schon 3 Jahre mit dem .Net Framework, da ist mir sowas noch nie passiert!
Für allgemeine Tipps bin ich natürlich auch sehr dankbar.
Ich würde mich über Hilfe sehr freuen.
MfG,
benjs