Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Compiler Error C2352 (VC++ 6.0)

  • 12-07-2004 01:17PM
    #1
    Registered Users, Registered Users 2 Posts: 1,253 ✭✭✭


    Hey everyone,

    Right... More Visual C++ questions.

    What I want to do is to override the CMainFrame::OnFileOpen() function.

    Now, I have come accros this problem before. Basically what I want to do is to be able to check the filename that the user has entered to determine if it is the correct type of file or not. So I have overridden the OnFileOpen() function with one of my own. This new function checks the filename and if it is correct then calls CDocument::OnOpenDocument().

    However, upon compiling I recieve an error saying that I cannot call a non-static member function from a static member function. I have had this problem before but I cant remember what it means or how I got around it.

    Can anybody shed some light on this for me? Its confusing for me! :o :dunno: :(


Comments

  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭Zab


    Static methods are not associated with an instance of a class, just the class itself. To call a non-static method, the call has to be associated with an instance. So, if you just try to call non_static_method() from within a static method, you'll get an error like this. Actually, MSDN should have a page explaining the error.


  • Registered Users, Registered Users 2 Posts: 1,253 ✭✭✭gobby


    Thanks for the reply Zab. Still, any ideas on how to get around this??


  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Make the function that's doing the calling static too? That's only a hack though...

    There's really no easy way to get around static/non-static errors like this, it's more a question of how you design things in the first place. A few rules of thumb (from CoderSource.net):
    • A static member function can access only static member data, static member functions and data and functions outside the class. A non-static member function can access all of the above including the static data member.
    • static member function can be called, even when a class is not instantiated, a non-static member function can be called only after instantiating the class as an object.
    • A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual.
    • static member function cannot have access to the 'this' pointer of the class.


  • Registered Users, Registered Users 2 Posts: 1,253 ✭✭✭gobby


    Cheers for the input lads.

    Had a look at the problem with a fella in my office. We kinda came up with a workaround. Its not exactly ideal but it (just about) has the desired effect.

    Well, I'm happy anyways! :D


Advertisement