Solved

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

Posted on 2007-03-22
4
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.

752 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