Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template overloading / nested class

Reply
Thread Tools

template overloading / nested class

 
 
Alexander Stippler
Guest
Posts: n/a
 
      07-24-2003
Hi,

Why is there no matching operator== in the following code?

#include <iostream>

template <class T>
class A
{
public:
template <class S>
class B;
};

template <class T>
template <class S>
class A<T>::B
{
};

template <class T, class A1, class A2>
bool
operator==(const typename A<T>::template B<A1> &lhs,
const typename A<T>::template B<A2> &rhs)
{
return true;
}

int
main()
{
A<int>::B<int> ab1;
A<int>::B<double> ab2;

std::cerr << (ab1 == ab2) << std::endl;
return 0;
}

regards,
alex
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      07-24-2003
"Alexander Stippler" <> wrote...
> Why is there no matching operator== in the following code?
>
> #include <iostream>
>
> template <class T>
> class A
> {
> public:
> template <class S>
> class B;
> };
>
> template <class T>
> template <class S>
> class A<T>::B
> {
> };
>
> template <class T, class A1, class A2>
> bool
> operator==(const typename A<T>::template B<A1> &lhs,
> const typename A<T>::template B<A2> &rhs)
> {
> return true;
> }
>
> int
> main()
> {
> A<int>::B<int> ab1;
> A<int>::B<double> ab2;
>
> std::cerr << (ab1 == ab2) << std::endl;
> return 0;
> }


I believe that behaviour is according with 14.8.2.4/4. Nested
types cannot be deduced.

Victor


 
Reply With Quote
 
 
 
 
Michael Kochetkov
Guest
Posts: n/a
 
      07-24-2003

"Alexander Stippler" <> wrote in message
news:...
> Hi,
>
> Why is there no matching operator== in the following code?
>
> #include <iostream>
>
> template <class T>
> class A
> {
> public:
> template <class S>
> class B;
> };
>
> template <class T>
> template <class S>
> class A<T>::B
> {
> };
>
> template <class T, class A1, class A2>
> bool
> operator==(const typename A<T>::template B<A1> &lhs,
> const typename A<T>::template B<A2> &rhs)
> {
> return true;
> }
>
> int
> main()
> {
> A<int>::B<int> ab1;
> A<int>::B<double> ab2;
>
> std::cerr << (ab1 == ab2) << std::endl;

I will take a risk to suppose a compiler cannot deduce template arguments.
All forms for which a compiler can deduce template type argument are listed
in 14.8.2.4/9. template_name<T1>::template_name<T2> is missing.

--
With regards,
Michael Kochetkov.


 
Reply With Quote
 
Rob Williscroft
Guest
Posts: n/a
 
      07-24-2003
Alexander Stippler wrote in news::

>
> Why is there no matching operator== in the following code?
>
>


Victor and Michael have already answered that.

I rewrote you code with a member operator==(), and it compiles
fine on 2/3 of the compilers I tested. Is there some reason
you need operator==() to be a non-member ?

#include <iostream>
#include <ostream>

template <class T>
class A
{
public:
template <class S>
class B;
};

template <class T>
template <class S>
class A<T>::B
{
public:

template <typename A2>
bool operator==(B<A2> const &rhs) const
{
return true;
}
};

int main()
{
A<int>::B<int> ab1;
A<int>::B<double> ab2;

std::cerr << (ab1 == ab2) << std::endl;
return 0;
}

HTH

Rob.
--
http://www.victim-prime.dsl.pipex.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Class nested inside a template class as template function argument type claudiu C Programming 2 04-01-2011 12:10 PM
problem with a function template returning a private nested class ofa class template ymost@hotmail.com C++ 2 12-28-2008 10:43 AM
operator-overloading of nested class inside a template class Gerhard Pfeiffer C++ 3 09-14-2006 06:46 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57