Error Illegal call of non-static member HELP


I am using VC++ 6 and I have an following MFC app.  There is an app iobject and a property sheet class.  On InitInstance in the app object I call the property sheets DoModal(); function.

What I am trying to do is when the the DoModal returns IDOK, i want to save some application settings to the registry.  But I have an error that is bugging me.  the error and the code I use are below

// TheApp class used for the main application

class TheApp : public CWinApp
  virtual BOOL InitInstance()
      #ifdef _AFXDLL

      CSheet ps;
      m_pMainWnd = &ps;

      if (ps.DoModal() == IDOK)

      return FALSE;

TheApp MyApp;

Note:  Page1 is a property class where the function is defined and it is the member variables of Page1 I want to save to the Registry
This is the compiler output

D:\Junk\LatestVersion\TheApp.cpp(158) : error C2352: 'Page1::SaveAppSettings' : illegal call of non-static member function
        d:\junk\latestversion\page1.h(27) : see declaration of 'SaveAppSettings'
Error executing cl.exe.

Can anybody help me.

LVL 12
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

As it is clear from the error message that you have tried to call a member function as static function. And that is illegal. Either you will have to define this function as static in the property page or save the state of the property page in property sheet object and then save the settings.
Problem with earlier approach is that you will not be access class memebers of the property page directly.
I would say, take the second approach.

if (ps.DoModal() == IDOK)

You might rather override the OnOK() function for the PropertySheet or property page and save your data from there. When you click the OK button in the dialog, this function will get called.
gbzhhuAuthor Commented:
Tried both the top suggestions, but with no success.

How do you which functions of MFC are static i.e is the OnInitDialog or OnInitInstance static?

And where a function is static does that mean I can't call my member functions.  if so how do I access my member functions then?

I even tried to override the OnOk of propertysheet and without calling another member function just use WriteProfileInt, but it comes with the same error.

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Just do your data saving operations in the OnOK() function directly (or call some helper function, which does not need to be static). Your member variables within the property sheet class can all be accessed directly from any member function of that class. You will not run into the problem of static vs. non-static functions that way:

    SaveMyStuff(); // this is a non-static member function in your class
} // end OnOK()

Static functions are "global" to all instances of your class - you would call them like so:


Non-static member functions are called via an instance of your class like so:

CYourClass c;

or with pointers like so:

CYourClass* pC = new CYourClass;

Try creating an object first:

Page1 page;

This usually works for me
gbzhhuAuthor Commented:

your answer does not tell memore than captainkirk's comment, so I will accept captainkirk's comment.

captainkirk can you put a dummy question so that I can give you the points

thanks, gbzhhu... you would need to first reject any outstanding answers and then another answer can be proposed...
gbzhhuAuthor Commented:

I am raedy for your dummy answer

OK, this is the dummy answer... thanks ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.