Error: Could not find a match for... ?

Hi,

I am trying to compile some code using Studio 10/11 which appears to compile cleanly using a bunch of different C++ compilers (xlC, aCC, VC, g++) but is failing using the C++ compiler in both Studio 10 and Studio 11 with:

"test.cpp", line 18: Error: Could not find a match for MKGeomT::getDistanceSquared<MKGeomT::_DIM, MKGeomT::_TYPE>(const MKGeomT::Segment<MKT::Dim2, MKT::Double>&, const MKGeomT::Point<MKT::Dim2, MKT::Double>&, MKGeomT::Point<MKT::Dim2, MKT::Double>*, double*).

"test.cpp", line 23: Error: Could not find a match for MKGeomT::getDistanceSquared<MKGeomT::_DIM, MKGeomT::_TYPE>(const MKGeomT::Segment<MKT::Dim3, MKT::Double>&, const MKGeomT::Point<MKT::Dim3, MKT::Double>&, MKGeomT::Point<MKT::Dim3, MKT::Double>*, double*).

Any ideas on how to get this to compile would be appreciated.

test.cpp:

/*

/opt/SUNWspro/bin/CC -library=stlport4 -c test.cpp

*/

#include "all.h"

namespace MKGeomT

{

template < class _DIM, class _TYPE >

double getDistanceSquared(Segment < _DIM, _TYPE > const &segment,

Point < _DIM, _TYPE > const &querypt,

Point < _DIM, _TYPE > *closestpoint,

double *param)

{ return 0.0; }

template double getDistanceSquared < MKT::Dim2 > (Segment2 const &segment,

Point2 const &querypt,

Point2 *closestpoint,

double *param);

template double getDistanceSquared < MKT::Dim3 > (Segment3 const &segment,

Point3 const &querypt,

Point3 *closestpoint,

double *param);

}

all.h:

// a.h

namespace MKGeomT

{

template < class _DIM, class _TYPE > class Point;

template < class _DIM, class _TYPE > class Segment;

template < class _DIM, class _TYPE >

double getDistanceSquared(Segment < _DIM, _TYPE > const &segment,

Point < _DIM, _TYPE > const &point,

Point < _DIM, _TYPE > *closestpoint /*= 0*/,

double *param = 0);

template < class _DIM, class _TYPE >

inline double getDistance(Segment < _DIM, _TYPE > const &segment,

Point < _DIM, _TYPE > const &point,

Point < _DIM, _TYPE > *closestpoint = 0)

{

return 0.0;

}

}

// b.h

namespace MKT

{

class Dim2{ public: enum { NUM_DIM = 2 }; };

class Dim3{ public: enum { NUM_DIM = 3 }; };

class Float { public: typedef float Stor_t; typedef double Calc_t; };

class Double { public: typedef double Stor_t; typedef double Calc_t; };

} // end of namespace MKT

// c.h

using MKT::Dim2;

using MKT::Dim3;

using MKT::Double;

namespace MKGeomT

{

template < class _DIM, class _TYPE >

class PointBase

{};

template < class _DIM, class _TYPE > class Point;

#if 1

template < class _TYPE >

class Point < Dim2, _TYPE > : public PointBase < Dim2, _TYPE >

{

};

template < class _TYPE >

class Point < Dim3, _TYPE > : public PointBase < Dim3, _TYPE >

{

};

#endif

typedef Point < Dim2, Double > Point2;

typedef Point < Dim3, Double > Point3;

} // end of namespace MKGeomT

// d.h

namespace MKGeomT

{

/*! The Segment is a geometry class storing a segment in 3-D. Things

like the segment vector and length are cached behind the

scenes so subsequent retrieval is a no-op. */

template < class _DIM, class _TYPE = MKT::Double >

class Segment

{};

template < class _DIM, class _TYPE >

double getDistanceSquared (Segment < _DIM, _TYPE > const &rkSeg0,

Segment < _DIM, _TYPE > const &rkSeg1,

double* pfSegP0 = 0,

double* pfSegP1 = 0);

template < class _DIM, class _TYPE >

double getDistanceSquared2(Segment < _DIM, _TYPE > const &rkSeg0,

Segment < _DIM, _TYPE > const &rkSeg1,

double* pfSegP0 = 0,

double* pfSegP1 = 0);

typedef Segment < MKT::Dim2, MKT::Double > Segment2;

typedef Segment < MKT::Dim3, MKT::Double > Segment3;

}

thanks,

k.m

[4445 byte] By [k.m] at [2007-11-26 9:53:30]
# 1
Files b.h, c.h and d.h are not referenced anywhere. The code as-is cannot be compiled. File c.h starts with some using-declarations with no prior includes or namespaces.Can you post an example that successfully compiles with some compiler?
clamage45 at 2007-7-7 1:10:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...
# 2

Never mind, I see that you intended to include b.h, c.h, and d.h in all.h.

Many compilers do not look at template code until the code is instantiated. This code consists only of declarations, with little that can be instantiated. It's possible that other compilers would also complain about this code if they got to the point of processing all the template declarations.

Can you add some instantiations along with template definitions and a main function so that the code can be compiled and linked?

clamage45 at 2007-7-7 1:10:19 > top of Java-index,Development Tools,Solaris and Linux Development Tools...