Topic: Nested non-templated class in templated class won't compile
Author: loose@astron.nl ("Marcel Loose")
Date: Thu, 12 Sep 2002 19:33:44 +0000 (UTC) Raw View
Hi all,
I stumbled upon a problem when using a non-templated nested class within a
templated class.
The GCC compiler reports an error (see code and diagnostics below), but I
don't see what wrong with this code.
It seems as if the compiler doesn't consider the operator() method to be a
member function.
Is this a compiler problem, or is this code wrong?
Marcel.
----------------------------------------------------
#include <vector>
template <class T>
class Templated
{
private:
typedef std::vector<T> buf_t;
class NonTemplated
{
public:
operator typename buf_t::size_type() const;
private:
typename buf_t::size_type myIndex;
};
};
template <class T>
Templated<T>::NonTemplated::operator typename
Templated<T>::buf_t::size_type() const
{
return myIndex;
}
int main()
{
Templated<int> tmpl;
return 0;
}
tTemplate.cc:19: no `Templated<T>::NonTemplated::operator std::vector<T,
std::allocator<_CharT> >::size_type() const' member function declared in
class `Templated<T>::NonTemplated'
tTemplate.cc:19: template definition of non-template `
Templated<T>::NonTemplated::operator std::vector<T,
std::allocator<_CharT>
>::size_type() const'
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: rogero@howzatt.demon.co.uk ("Roger Orr")
Date: Thu, 12 Sep 2002 23:02:13 +0000 (UTC) Raw View
""Marcel Loose"" <loose@astron.nl> wrote in message
news:alpmlt$1sf6tt$1@ID-64911.news.dfncis.de...
> Hi all,
>
> I stumbled upon a problem when using a non-templated nested class within a
> templated class.
[snip]
> Is this a compiler problem, or is this code wrong?
I believe this code is correct, and you've got a compiler bug.
However this problem can be worked around by making the operator
inline -which also works around
a similar restriction in Microsoft VC6 and VC7.
Roger Orr
--
MVP in C++ at www.brainbench.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]