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


begin 0644 Cross.txt
M+R]#<F]S<RYH#0HC:69N9&5F($-23U-37TQ)3DM%1%],25-4#0HC9&5F:6YE
M($-23U-37TQ)3DM%1%],25-4#0H-"G1E;7!L871E(#QT>7!E;F%M92!4/ T*
M8VQA<W, 0W)O<W,-"GL-"G!U8FQI8SH-" E#<F]S<R I.PT*"4-R;W-S*&EN
M="!M+"!I;G0 ;BD[#0H)?D-R;W-S*"D[#0H-" EI;G0 36]D:69Y*&EN="!M
M+"!I;G0 ;BP 8V]N<W0 5"8 :71E;2D[#0H)5"!$96QE=&4H:6YT(&TL(&EN
M="!N*3L-" EI;G0 1V5T*&EN="!M+"!I;G0 ;BP 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E<G0 *%]P0W)O<W, )B8 7W!.;V1E*3L-" ER971U<FX 
17W!.;V1E+3YC;VP[#0I]#0IP
`
end
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