
Originally Posted by
ArdentAngel
Oh, and the models array should having this kind of values:
PHP Code:
$models['object1']['x'] = 7831;
$models['object2']['x'] = 1893;
To add to SMA's example:
Code:
#include <map>
#include <string>
#include <iostream>
template <typename T>
struct Point
{
T x;
T y;
T z;
Point(T theX = T(), T theY = T(), T theZ = T()) : x(theX), y(theY), z(theZ) {}
};
typedef std::map<std::string, Point<double> > FloatModels;
typedef std::map<std::string, Point<int> > IntModels;
using namespace std;
int main()
{
FloatModels models;
IntModels models2;
models["object1"] = Point<double>(); // defaults to 0.0
models["object2"] = Point<double>(3.0, 2.0, -1.9);
models2["object1"] = Point<int>(); // defaults to 0
models2["object2"] = Point<int>(3, 2, -1);
cout << "Here are the floating point coordinates:\n";
FloatModels::iterator it = models.begin();
while (it != models.end() )
{
cout << it->first << " -> " << "(" << it->second.x << ", " << it->second.y << ", " << it->second.z << ")\n";
++it;
}
cout << "\nHere are the integer point coordinates:\n";
IntModels::iterator it2 = models2.begin();
while (it2 != models2.end() )
{
cout << it2->first << " -> " << "(" << it2->second.x << ", " << it2->second.y << ", " << it2->second.z << ")\n";
++it2;
}
}
Output:
Here are the floating point coordinates:
object1 -> (0, 0, 0)
object2 -> (3, 2, -1.9)
Here are the integer point coordinates:
object1 -> (0, 0, 0)
object2 -> (3, 2, -1)
Regards,
Paul McKenzie