Solved

Accessing a class private data members from a Form class in an MFC project

Posted on 2007-03-22
4
224 Views
Last Modified: 2013-11-26
Hello,
I have a class Form2 in my MFC project which is defined as :
class Dee_Form2 : public CDialog
{
    Load ld ;
// code for class' data and functions
}

I have another class called Load in the project which has prvate data and public member functions. I need to be able to acess most of the private data members of load through form 2 . I dont want to have to write a get member function to return a data member from the Load class. Whats the workaround?  
Thanks
-D
0
Comment
Question by:indacrypt
  • 2
4 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18772968
Have the members you need to access as public members.
0
 

Author Comment

by:indacrypt
ID: 18773574
no..that just defeats the purpose.....aah i think ill just have to write those get functions.
0
 
LVL 9

Accepted Solution

by:
smidgie82 earned 125 total points
ID: 18773584
Alternatively, declare class Form2 as a friend of class Load:

#include "form2.h"

class Load
{
    friend class Form2;

public:
.
.
.

private:
/* private data here */
}

Then any member of an instance of Form2 (or static members of Form2) should have access to the protected and private data and functional members of Load.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 18773596
I don't think .net supports 'friend' classes.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now