Re: Templating classes
MathStuf wrote:
On Jun 1, 5:11 pm, red floyd <no.s...@here.dude> wrote:
MathStuf wrote:
[redacted]
Hmm...guess I should have looked exactly where it was getting mixed
up there. It's in the following code:
template<class T> class Matrix : public MatrixBase<T>
{
public:
Matrix()
{
width = 0;
height = 0;
matrix.clear();
}
// More methods
};
Note that since width and height are members of MatrixBase<>, it's
probably better to let MatrixBase set them. If you need something
other than what MatrixBase has set as the "default", MatrixBase
should have a constructor with width and height parameters.
Alright, but I still have problems with their availability. I have
GetWidth() and GetHeight() methods in MatrixBase<>, but when i go to
call it, the compiler complains about it.
\Matrix.h:161: error: there are no arguments to `GetHeight' that
depend on a template parameter, so a declaration of `GetHeight' must
be available
That's just not true. 'GetHeight' is non-static, so it *does* have
one argument that depends on the template argument - the instance of
the class (the object). But it doesn't really matter. The full name
of 'GetHeight' is 'MatrixBase<T>::GetHeight', which means it *does*
depend on 'T' (simply because it is a member of the template).
I'm confused since MatrixBase<T> is inherited as public, and protected
members should be available (as well as public ones such as
GetHeight() and GetWidth()). I have other classes (non-template
though)
That's *the* difference.
where an id is inherited from the base class (public
inheritance of a protected variable) and straight calls to the id
works. Do templates mess with inheritance at all?
No, but they do have slightly different rules for name lookup.
I don't think they
would, but that's what it would seem is happening here.
No, you just need to learn name lookup rules.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask