473,569 Members | 2,747 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 1828
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
3130
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 friend classes as "friend ClassName", which is easy to remedy by replacing "friend" with "friend class". But this poses another problem: in the file...
12
3233
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 private. I have placed "friend void CA::Run_A(void)" in CMain Class. CMain::Run() function attempts to execute CA::Run_A(), but compiler shows an error...
6
2325
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 data from the class. Here's the gist of the code: template <class T> struct NodeType { T data; NodeType<T> * link;
4
2437
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 far is pretty simple: using an idea of Andrei Alexandrescu (at least that's where I first read it) to create a lightweight way of overloading...
7
1938
by: Mark P | last post by:
Is this legal and sensible? class Outer { friend struct Inner { ... }; ...
1
1423
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 created. But, I can't get the friend class to work. For example (this is not actually my code): template <typename Key, typename Value> class...
6
2045
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
1682
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
2149
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
3154
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 void func()
0
7694
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6278
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2107
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 we have to send another system

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.