This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/19288] No more possible to have a template function that uses a nested class of a template class
- From: "jean-pierre dot chevallet at imag dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 10 Jan 2005 05:56:30 -0000
- Subject: [Bug c++/19288] No more possible to have a template function that uses a nested class of a template class
- References: <20050106084006.19288.jean-pierre.chevallet@imag.fr>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From jean-pierre dot chevallet at imag dot fr 2005-01-10 05:56 -------
(In reply to comment #7)
> You are trying to overload operator<<(std::ostream, float). That
> can't work, since there is already an overload for that.
>
> W.
I don't think so, I try to define un fonction like this :
operator<<(std::ostream, C1<float>::nested&) with is not an overload of
operator<<(std::ostream, float).
The lesson I learn from all your replies :
nested class of a template wich have no template
parametrer are difficult to use due to the notion nondeducible context.
I think it is better to avoid non template nested class, or adding a
explicit template parameter to the nested class, like :
template <typename T> class C1 {
public:
T V;
C1(T v) : V(v) {};
template <typename U>
class nested {
public:
U W;
nested(U w) : W(w) {};
};
};
// Template version of operator using nested temptate class
template <typename T>
ostream& operator << (ostream& out,typename C1<T>::nested<T>& c) {return
out<<c.W; }
C1<float>::nested<float> n(3.5);
cout<<n<<endl; // Here find the correct instantiation
or not use nested template class at all ........
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19288