I am implementing a Boundary Volumn Hierarchy structure, where the tree has a template like this:
template <typename Coordinate>
class BoundingTree { /* ... */ }
The Coordinate
can be Vector2d
, Vector3f
or any other arbitrary coordinate. To use this BoundingTree
structure for collision detection, there should be an detection function:
template <typename Coordinate>
template <typename RigidBody>
bool BoundingTree::collide(RigidBody const & body);
The RigidBody
can be everything, e.g. Cuboid3f
, Circle2d
. And my implementation of this detection system is:
// BoundingTree.h
template <typename Coordinate>
class BoundingTree
{
public:
BoundingTree() {}
// collide function decleration
template <typename RigidBody>
bool collide(RigidBody const & obj);
};
// BoundingTree.cpp
// specilizations
template<typename Coordinate> template <typename RigidBody>
bool BoundingTree::collide(RigidBody const & obj)
{
std::cout << "default" << std::endl;
return false;
}
template<> template<>
bool BoundingTree<Vector3f>::collide<Sphere3f>(Sphere3f const & d)
{
std::cout << "Vector3f Sphere3f" << std::endl;
return 1;
};
template<> template<>
bool BoundingTree<Vector3f>::collide<Cuboid3f>(Cuboid3f const & d)
{
std::cout << "Vector3f Cuboid3f" << std::endl;
return 1;
};
But I got an Error:
1>BoundingTree.cpp(6): error C2955: 'BoundingTree': use of class template requires template argument list
1> BoundingTree.h(32): note: see declaration of 'BoundingTree'
1>BoundingTree.cpp(10): error C2244: 'BoundingTree::collide': unable to match function definition to an existing declaration
1> BoundingTree.cpp(6): note: see declaration of 'BoundingTree::collide'
How to solve this problem?
Is there any better manner to implement this collision detection system with arbitrary types?
Thanks a lot.