H
homsan toft
I've tried the below code with MSVC and Comeau online compiler.
Both complain that operator<< for Outer<part<size_t> >::inner is not defined.
So how do I declare it without doing full specialization?
I've tried a template on any type, like Outer<AnyT>::inner (see below)
Also tried a template on the templated type: Outer<part<X> >::inner // (see below)
I can't find a typo? What is the rule in operation here?
Thanks,
homsan
---------------- 8< -----------------
#include <iostream>
template<class SizeT>
struct part {
typedef SizeT size_type;
size_type size;
};
template<class PartT>
class Outer
{
public:
typedef PartT part_type;
struct inner {
part_type p;
};
inner get() const { return inner(); }
};
// WHY is this not found in main()?
template<class PartT>
inline std:
stream& operator<<(std:
stream& ostr, typename Outer<PartT>::inner const& it)
{
ostr << it.p.size << " by Jove\n";
return ostr;
}
// Nor is this found - what gives?
template<class SizeT>
inline std:
stream& operator<<(std:
stream& ostr, typename Outer<part<SizeT> >::inner const& it)
{
ostr << it.p.size << " by Jove\n";
return ostr;
}
// Now this works, but of course I don't want to redefine for every specialization...
/*
std:
stream& operator<<(std:
stream& ostr, Outer<part<size_t> >::inner const& it)
{
ostr << it.p.size << " by Jove\n";
return ostr;
}
*/
int main() {
Outer<part<size_t> > yippie;
std::cout << yippie.get();
return 0;
}
Both complain that operator<< for Outer<part<size_t> >::inner is not defined.
So how do I declare it without doing full specialization?
I've tried a template on any type, like Outer<AnyT>::inner (see below)
Also tried a template on the templated type: Outer<part<X> >::inner // (see below)
I can't find a typo? What is the rule in operation here?
Thanks,
homsan
---------------- 8< -----------------
#include <iostream>
template<class SizeT>
struct part {
typedef SizeT size_type;
size_type size;
};
template<class PartT>
class Outer
{
public:
typedef PartT part_type;
struct inner {
part_type p;
};
inner get() const { return inner(); }
};
// WHY is this not found in main()?
template<class PartT>
inline std:
{
ostr << it.p.size << " by Jove\n";
return ostr;
}
// Nor is this found - what gives?
template<class SizeT>
inline std:
{
ostr << it.p.size << " by Jove\n";
return ostr;
}
// Now this works, but of course I don't want to redefine for every specialization...
/*
std:
{
ostr << it.p.size << " by Jove\n";
return ostr;
}
*/
int main() {
Outer<part<size_t> > yippie;
std::cout << yippie.get();
return 0;
}