473,503 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

friend class problem

Hi All,

I have problem regarding the friend class.
I have a library where the class are declration is follows ( only
example )

class Frame
{
public:
protected:
void printFramemsg()
{
cout << " test... " << endl;
}
private:

// by making this we can access the protected members in the view

friend class View;
};

class View
{
public:
void setFrame(Frame* aFrame)
{
myFrame = aFrame;
}
void print()
{
myFrame->printFramemsg();
}
protected:
Frame* myFrame;
};

Now I want to derive the View class and access the protected and private
members of the Frame class..

class myView : public View
{
public:
void print_1()
{
myFrame->printFramemsg();
}
private:
};

Is any workarround or other way to do this .. ( Here I do not want to
derive a class from Frame ... )

Bye
Chandra

Jul 22 '05 #1
2 1820
chandra sekhar wrote:

class View
{
public:
void setFrame(Frame* aFrame)
{
myFrame = aFrame;
}
void print()
{
myFrame->printFramemsg();
}
protected:
Frame* myFrame;
};

Now I want to derive the View class and access the protected and private members of the Frame
class..
Why?
The Frame class has a public interface. You ought to use that, that's why
it exists.

class myView : public View
{
public:
void print_1()
{
myFrame->printFramemsg();


myView is not a friend of the frame. But View (the base class of myView)
is. Thus:

View::print();
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #2
Dear Chandra,

There is no way for inheritance of friendship. So, you have to make the
derived class a also a friend.
With private members there is no other way.
But with protected members I don not know, as I never had to use friends.

I would derive a class MyFrame from Frame. Here you can access the protected
member of Frame. Make the function for accessing public and you need no
friends - or make it protected or private and make MyView a friend of
MyFrame.

Greetings
Ernst
Jul 22 '05 #3

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

Similar topics

1
3122
by: Alex Borghgraef | last post by:
Hi all, I'm trying to get the Limp (Large Image Manipulation Program) library to compile using gcc 3.2, and I've encountered some problems. One is that the library systematically refers to...
12
3215
by: Bryan Parkoff | last post by:
CMain Class is the base class that is initialized in main function. CA Class is the base class that is initialized in CMain::CMain(). CMain Class is always public while CA Class is always...
6
2320
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...
4
2436
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...
7
1931
by: Mark P | last post by:
Is this legal and sensible? class Outer { friend struct Inner { ... }; ...
1
1411
by: Joe Carner via .NET 247 | last post by:
First time posting, thanks in advance for any help you can give me. Basically I am trying to a class that i want to be able to access the private data members of another class, both of which i...
6
2039
by: Joseph Turian | last post by:
I am having difficulty defining a friend function because of a #include cycle: ============ obj.H ================ #ifndef _obj_ #define _obj_ #include "cont.H" class cont;
1
1674
by: Jess | last post by:
Hello, I am trying to define a friend function for my class as follows: #include<iostream> using namespace std; class B;
5
2137
by: Amit Gupta | last post by:
How do I do it (either by friend or by any other hack). I have three class, I am just writing derivation below: class A{} class B{} class C : public class B{} class D: public class B ()
6
3148
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend...
0
7064
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
7261
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,...
1
6974
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...
0
7445
tracyyun
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...
0
5559
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,...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
369
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.