Let's say we have a class template:
template< typename t >
class c;
and a function template:
template< typename t1, typename t2 >
bool operator ==
(
c< t1 > const&
, c< t2 > const&
);
Now we want operator ==< t1, t2 > to be a friend of class c< t3 > ONLY for t1 = t3 or t2 = t3. How do we specify this? 5 2061
Angel Tsankov wrote: Let's say we have a class template:
template< typename t > class c;
and a function template:
template< typename t1, typename t2 > bool operator == ( c< t1 > const& , c< t2 > const& );
Now we want operator ==< t1, t2 > to be a friend of class c< t3 > ONLY for t1 = t3 or t2 = t3. How do we specify this?
It is only available if you specialise your 'c' for 't3'. You cannot
declare friendship outside any class definition.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
>> Let's say we have a class template: template< typename t > class c;
and a function template:
template< typename t1, typename t2 > bool operator == ( c< t1 > const& , c< t2 > const& );
Now we want operator ==< t1, t2 > to be a friend of class c< t3 > ONLY for t1 = t3 or t2 = t3. How do we specify this?
It is only available if you specialise your 'c' for 't3'. You cannot declare friendship outside any class definition.
What if we have access to the definition of c<t >?
Angel Tsankov wrote: Let's say we have a class template:
template< typename t > class c;
and a function template:
template< typename t1, typename t2 > bool operator == ( c< t1 > const& , c< t2 > const& );
Now we want operator ==< t1, t2 > to be a friend of class c< t3 > ONLY for t1 = t3 or t2 = t3. How do we specify this?
It is only available if you specialise your 'c' for 't3'. You cannot declare friendship outside any class definition.
What if we have access to the definition of c<t >?
Fine. If you declare operator==() a friend of the original template,
then it will be a friend of _all_ instantiations of that template.
V
--
Please remove capital As from my address when replying by mail
"Victor Bazarov" <v.********@comAcast.net> wrote in message news:ke******************************@comcast.com. .. Angel Tsankov wrote: Let's say we have a class template:
template< typename t > class c;
and a function template:
template< typename t1, typename t2 > bool operator == ( c< t1 > const& , c< t2 > const& );
Now we want operator ==< t1, t2 > to be a friend of class c< t3 > ONLY for t1 = t3 or t2 = t3. How do we specify this?
It is only available if you specialise your 'c' for 't3'. You cannot declare friendship outside any class definition.
What if we have access to the definition of c<t >?
Fine. If you declare operator==() a friend of the original template, then it will be a friend of _all_ instantiations of that template.
Right, this is what I do not want. I want operator ==<t1,t2> to be a friend of c<t> ONLY for t1 = t3 or t2 = t3.
Angel Tsankov wrote: "Victor Bazarov" <v.********@comAcast.net> wrote in message news:ke******************************@comcast.com. .. Angel Tsankov wrote:> Let's say we have a class template: > > template< typename t > > class c; > > and a function template: > > template< typename t1, typename t2 > > bool operator == > ( > c< t1 > const& > , c< t2 > const& > ); > > Now we want operator ==< t1, t2 > to be a friend of class c< t3 > > ONLY for t1 = t3 or t2 = t3. How do we specify this?
It is only available if you specialise your 'c' for 't3'. You cannot declare friendship outside any class definition.
What if we have access to the definition of c<t >? Fine. If you declare operator==() a friend of the original template, then it will be a friend of _all_ instantiations of that template.
How can we do that? Can we declare a template as a friend of another
template?
Right, this is what I do not want. I want operator ==<t1,t2> to be a friend of c<t> ONLY for t1 = t3 or t2 = t3.
template <class t>
class SomeTemplateClass {
friend bool operator ==<t, t3>(t&, t3&);
friend bool operator ==<t3, t>(t3&, t&);
// rest of the class declarations
};
Assuming t3 is known, won't the above code ensure that the operator ==
is a friend if and only if one of the arguments is of type t3? No? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Stippler |
last post by:
Hi
what's wrong about the following code? It does not compile.
template <typename T>
class A {
public:
class B;
};
|
by: Sebastian Faust |
last post by:
Hi,
is a construction like the following possible:
template<class view_model>
class template_clase
{
protected:
template_clase() {}
virtual ~template_clase() {}
|
by: Dmitry D |
last post by:
Hi all,
I'm having problems with declaring a template friend function. It seems like
I've done everything as explained
in C++ FAQ, but still, I'm getting the linker error (unresolved external...
|
by: Ben Ingram |
last post by:
Hi all,
I am writing a template matrix class in which the template parameters are
the number of rows and number of columns. There are a number of reasons
why this is an appropriate tradeoff for...
|
by: James Aguilar |
last post by:
Hello, all.
I saw this in the provided code of a lab that I have due in a couple of
weeks in my algorithms class. It compiled fine in g++ but did not compile
with the VC++ compiler. It does...
|
by: BigMan |
last post by:
I have a class template like this:
template< typename t >
class c;
I'd also like to have an operator == for objects of types, which are
different specializations of c:
template< typename...
|
by: Zeng |
last post by:
It's so messy w/o the "friend" relationship. Does anyone know why it was
not supported in C#. It's almost about as bad as it doesn't support the
inheritance hierarchy and method reference...
|
by: truce |
last post by:
I searched but couldn't find anything _quite_ like this. I have some
code I inherited that needs some work. Basically I have a template
that is instantiated in the c++ code and so only the...
|
by: Adam Badura |
last post by:
I have code like this
template<int size> big_int {
/* ... */
template<int size2> friend class big_int<size2>;
};
What I wanted to achive is to be able to easly convert different sized...
|
by: H9XLrv5oXVNvHiUI |
last post by:
Hi, I have a question about injecting friend functions within template
classes. My question is specific to gcc (version 3.4.5) used in
combination with mingw because this code (or at least code...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
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,...
| |