Following 14.5.3, I tried:
class A
{
template<class T> friend class B;
};
where A is a simple non-template class and B is a template.
I tried to use a private method in B from a method in A.
Using gcc-3.2, this fails at compile time, but succeeds
when the method in B is made public.
Is this a compiler bug, or am I missing something?
Thanks for your help.
Mike. 3 2215
"Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... Following 14.5.3, I tried:
class A { template<class T> friend class B; };
where A is a simple non-template class and B is a template. I tried to use a private method in B from a method in A.
I think you are mistaken about the friendship _direction_.
In the situation you showed, 'B' is a friend of 'A', which
means that any member function of 'B' has access to private
members of 'A', not the other way around. Using gcc-3.2, this fails at compile time, but succeeds when the method in B is made public.
Is this a compiler bug, or am I missing something?
You're missing something.
Victor
Victor Bazarov wrote: "Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... Following 14.5.3, I tried:
class A { template<class T> friend class B; };
where A is a simple non-template class and B is a template. I tried to use a private method in B from a method in A.
I think you are mistaken about the friendship _direction_. In the situation you showed, 'B' is a friend of 'A', which means that any member function of 'B' has access to private members of 'A', not the other way around.
Using gcc-3.2, this fails at compile time, but succeeds when the method in B is made public.
Is this a compiler bug, or am I missing something?
You're missing something.
Victor
My mistake, I tried to use a method in A from the template B.
Am I still missing something?
Sorry,
Mike.
On Fri, 21 Nov 2003 07:15:11 -0500, Mike - EMAIL IGNORED
<m_*************@yahoo.com> wrote:
Victor Bazarov wrote: "Mike - EMAIL IGNORED" <m_*************@yahoo.com> wrote... > Following 14.5.3, I tried: > > class A > { > template<class T> friend class B; > }; > > where A is a simple non-template class and B is a template. > I tried to use a private method in B from a method in A.
I think you are mistaken about the friendship _direction_. In the situation you showed, 'B' is a friend of 'A', which means that any member function of 'B' has access to private members of 'A', not the other way around.
> > Using gcc-3.2, this fails at compile time, but succeeds > when the method in B is made public. > > Is this a compiler bug, or am I missing something?
You're missing something.
Victor
My mistake, I tried to use a method in A from the template B. Am I still missing something?
Yes, this compiles fine in GCC 3.2:
class A
{
template<class T>
friend class B;
int i; //private
};
template <class T>
class B
{
public:
int f()
{
A a;
a.i = 5; //private access
return a.i;
}
};
int main()
{
B<int> b;
b.f();
}
Tom This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Christophe Barbe |
last post by:
I posted a few days ago about the same problem but was not very clear. So
here is my second take at it.
Basically with GCC 3.3.2, I can't compile the example from the
C++ FAQ Lite available...
|
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: Adam Parkin |
last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue
class I'm writing using linked lists. The problem is that I can't get the
friend function to be able to access private...
|
by: Ruben Campos |
last post by:
I have a problem with a template function that is declared as a friend of a
template class. I'll first show the exact problem with source code:
// MyClass.hpp
template <typename T>
class...
|
by: Justin Miller |
last post by:
Ok, I tried to make that subject as descriptive as possible.
What I'm trying to do:
I'm attempting to use policies to create a generic memento (design
pattern) template. My Memento template so...
|
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...
|
by: coolpint |
last post by:
Can anyone kindly provide an explanation as to why the compiler does
not "see" the function template in the contrieved code below?
I think the argument deduction fails but can't figure out...
|
by: Hamilton Woods |
last post by:
Diehards,
I developed a template matrix class back around 1992 using Borland C++ 4.5
(ancestor of C++ Builder) and haven't touched it until a few days ago. I
pulled it from the freezer and...
|
by: Alan Woodland |
last post by:
I've been trying out more template metaprogramming ideas with typelists
(mostly for personal learning, I'm aware boost most probably provides
this facility already), and I've run into this small...
|
by: wo3kie |
last post by:
#include <iostream>
#include <map>
#include <utility>
//
// Base
// / | \
// Derived1 Derived2 \
// \ | /
// Derived3
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |