[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with deriving from stream templates
From: |
Bernd Strieder |
Subject: |
Re: Problem with deriving from stream templates |
Date: |
Tue, 17 Jun 2008 13:45:24 +0200 |
User-agent: |
KNode/0.10.4 |
Hello,
Dan Smithers wrote:
> I want to write my own class derived from the ostream class.
>
> I have been getting errors with my templates:
>
> First, I get an error writing a nested template. If I leave the
> function definition inside template class definition (commented out at
> //1) then it compiles and runs fine, but if I declare and define the
> function separately (at //2).
>
> Is the following syntax supported by g++?
> template<typename charT, typename Traits>
> template<typename T>
> as I get the compiler error
> "mystream.cpp:47: error: too many template-parameter-lists"
You have to declare the function you intend to become a friend before
the template class. Since the template class itself is in the
interface of that function, you habe to forward declare the template
class.
template <typename charT, typename Traits=std::char_traits<charT> >
class CMyStream;
template <typename charT,
typename Traits = std::char_traits<charT> ,
typename T>
CMyStream<charT, Traits>& operator<<(CMyStream<charT, Traits>& ostr,
T val);
This problem is a gcc-ism only as far as gcc started to be more
strict along the lines of the standard. You'd better ask in some
general newsgroup like comp.lang.c++(.moderated), or even their
FAQs.
Can't help on the other problems now.
Bernd Strieder