473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

template overloading / nested class

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
Jul 19 '05 #1
3 2612

"Alexander Stippler" <st**@mathematik.uni-ulm.de> wrote in message
news:3f******@news.uni-ulm.de...
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.
Jul 19 '05 #2
"Alexander Stippler" <st**@mathematik.uni-ulm.de> 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
Jul 19 '05 #3
Alexander Stippler wrote in news:3f******@news.uni-ulm.de:

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/
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: porschberg | last post by:
Hi, I have a template class that looks like: template <class T> class Update { friend otl_stream& operator<< (otl_stream&, const shared_ptr<typename T::row>&); friend ostream& operator<<...
5
by: Arkadiy Vertleyb | last post by:
Hi all, I am having a problem trying to overload a function template, based on a typedef, such as: template<class T> struct A {}; template<class T>
9
by: Jon Wilson | last post by:
I have a class which needs to accumulate data. The way we get this data is by calling a member function which returns float on a number of different objects of different type (they are all the...
3
by: CoolPint | last post by:
After upgrading to gcc 3.4.2 from gcc 3.2.3, I got compiler errors that I could not figure out. After reading other postings, I learned that my coding was not compliant to the standard in the first...
11
by: gao_bolin | last post by:
I am facing the following scenario: I have a class 'A', that implements some concept C -- but we know this, not because A inherits from a virtual class 'C', but only because a trait tell us so: ...
2
by: Greg Buchholz | last post by:
/* I've been experimenting with some generic/polytypic programs, and I've stumbled on to a problem that I can't quite figure out. In the program below, I'm trying to define a generic version of...
7
by: quarup | last post by:
I want to specialize a template function that lives inside a class, but am getting a compile error in VS.net 2003. Here's my code: template <class T> class A { public: template <class U> void...
3
by: Gerhard Pfeiffer | last post by:
Hi, I'm trying to implement a data-structure and have an iterator for it. Now I've got a problem impleneting the operator+. I tried to isolate the problem: template<int DIM, typename Tclass...
5
by: huili80 | last post by:
For example, like in the following, the part commented out was intended as partial spectialzation, but it would even compile. Is it even legal to partially specialize a nested template class...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.