Jun 9, 2011 at 5:46pm UTC
If it will be easy for you to help me i could post all relevant/working code to compile yourself?
Jun 9, 2011 at 6:04pm UTC
savavampir and what you think what type should be T in template function IsInsideRect??..I haven't compiler in this computer but i think in this case you must mention type like for example this IsInsideRect<type>()......
Jun 9, 2011 at 6:10pm UTC
1 2 3 4 5 6 7 8 9 10 11 12
template <typename T>
class Rect
{
private :
Point<T> ul;//as upper left
Point<T> lr;//as lower right
public :
...//ctor's & standard operators
...
friend bool IsInsideRect(const Point<T>& p, const Rect<T>& r);
};
That declaration of IsInsideRect above does not make it a template function - so this definition
1 2 3 4 5 6
template <typename T>
bool IsInsideRect(const Point<T>& p, const Rect<T>& r)
{
// i have implemented >, <, >=, <= operators for Point
return ((p > r.ul) && (p < r.lr));
}
will not match
EDIT:
So bascially you need to make the friend declaration a template.
Last edited on Jun 9, 2011 at 6:30pm UTC
Jun 9, 2011 at 6:36pm UTC
Still can't resolve this, this i have tried:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
template <typename T >
class Rect
{
...
template <typename U >
friend bool IsInsideRect(const Point<U >& p, const Rect<U >& r);
};
template <typename U >
bool IsInsideRect(const Point<U >& p, const Rect<U >& r)
{
return ((p > r.ul) && (p < r.lr));
}
...
//main.cpp
Point<LONG> pt(5, 5);
Rect<LONG> rc(Point<LONG>(0, 0), Point<LONG>(20, 20));
if (IsInsideRect<LONG> (pt, rc))
{
MessageBox(0, "POINT IS INSIDE" , "MESSAGE" , 0);
}
and still same error. Can't see what's wrong???
Last edited on Jun 9, 2011 at 6:38pm UTC
Jun 9, 2011 at 7:10pm UTC
Thanks, that works. The difference that i had in my code is that my Point (>, <, <=...operators) was declared as friend's and definition was in cpp file. Now when i bring it in class body without change to IsInsideRect function it works.