hye all
I have class CScenDoc . In that class have function called ONSEND() where I am doing certain operation .I want to call this ONSEND function in other function which is not a member function any class ,its a seperate function. How can i call ONSEND function onto that function .I know through friend function but getting some error

You need a CScenGenDoc object, let's call it x, then you can do x.OnSend();, or if x is a pointer to CScenGenDoc then you would do x->OnSend();

If you want to call the function without the object existing then you need to make the function static, then it can be called with CScenGenDoc::OnSend();

You would only need to make landmove() a friend of CScenGenDoc if CScenGenDoc::OnSend() is private or protected. However if that's the case then the designer of CScenGenDoc really didn't mean you to be calling that function directly so you should discuss with the designer how you can access that functionality. If it turns out that CScenGenDoc::OnSend() can be public after all then make it public and don't make landmove() a friend of CScenGenDoc.

answerme

20Oct2009 10:41

Re: friend function

Thank for reply
Since Onsend() function is public in class CScenGenDoc( ScenGenDoc.h) I called CScenGenDoc::OnSend(); in landmovement .cpp file,but its genrating a error

error C2352: 'CScenGenDoc::OnSend' : illegal call of non-static member function
I have given header file also #include "ScenGenDoc.h" in landmovement.cpp

Is it because the class it self is protected.Plz advice me where iam wrong

xpi0t0s

20Oct2009 12:21

Re: friend function

> illegal call of non-static member function

Yes. That's because it's not static and you're trying to call the function without an object.
Make the function static - as I said in my last post and as the error is telling you - and it will work.
It's not enough for it to be public; it must be static as well.

This is because of the way the object oriented methodology works: if an object doesn't exist, then its methods don't exist either.