Solved

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

Posted on 2007-03-22
4
226 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

864 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

21 Experts available now in Live!

Get 1:1 Help Now