www.digitalmars.com         C & C++   DMDScript  

c++ - nest template class

reply Michael <Michael_member pathlink.com> writes:
Hello, I'm a dm user. I run into a problem these days. It may be a simple
question in your eyes, but please give me a hand.
It's a nest template class question. In VS.net 2003 and gcc, it can be compiled
and works well. But in dm errors happen when being compiled. This is what I have
done:

//in Cross.h
template <typename T>
class Cross
{
public:
..
class Iterator
{
public:
..
const T& operator*() const;
const typename
Cross<T>::Iterator operator++(int);
//and overload some operators like this
};
friend class Iterator;
Iterator Row(int m = 0) const;
Iterator Row_end() const;
protected:
..
};
//and in Cross.cpp
#include "Cross.h"
..
template <typename T>
const T& Cross<T>::Iterator::operator*()
{
..
}
template <typename T>
const typename Cross<T>::Iterator
Cross<T>::Iterator::operator++(int)
{
..
}
//then in main.cpp
#include "Cross.cpp"
int main()
{
Cross<int> mat;
..
}

When compiled: dmc main.cpp
it prints errors:
template <typename T>
^
Error: 'Iterator' is not a class template 
Mar 07 2005
next sibling parent reply "Walter" <newshound digitalmars.com> writes:
Looks like a compiler bug. I'll take care of it. Thanks, -Walter
Apr 04 2005
parent Michaelgs <Michaelgs_member pathlink.com> writes:
I wish my code would help you debug, or you may find that I made the mistake
somewhere, not the compiler.
P.S
It prints: (when meeting any operator overloading from 'operator*' on, but
'operator=' passes successfully)
template <typename T>
^
Error: 'Iterator' is not a class template
Apr 08 2005
prev sibling parent "Walter" <newshound digitalmars.com> writes:
I've got it fixed now, it'll go out in the next beta. Thanks, -Walter
Apr 20 2005