Thread: Error c2352 in MSVC6

  1. #1
    Unregistered
    Guest

    Error c2352 in MSVC6

    Hello,

    I am new to C++ and VS but have written a few programs in c before.

    When I try to compile a single dialog (Form) application I get
    "error C2352: 'CUserinfo3App::WriteCancelled' : illegal call of non-static
    member function"

    I trying to call a function in a class derived from CWinApp from another
    class.

    Some MSKB articles say this is a bug which goes back to VC++4 but I'm I
    running VC6 with SP5.
    Surely this bug must have been fixed by now! or am I just making a mistake?
    (I suspect I am)

    Any help or pointers appreciated as I'm kinda stuck.

    P..

  2. #2
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Can you post the section of code that the error refers to?

  3. #3
    Unregistered
    Guest
    void CUserinfo3App::WriteCancelled()
    {

    CUserinfo3App::SetRegistryKey("SomeCompany") ; error here
    CUSerinfo3App::WriteProfileString ("LastResult", "Operation", "Cancelled By User") ; error here

    char CancelTitle[] = "FYI";
    MessageBox( NULL, CancelText, CancelTitle, MB_OK);
    }

    CUser3App was derived from CWinApp as public

    P..

  4. #4
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Sorry for stating the obvious, but is CUserinfo3App::WriteCancelled declared as a static member function?

  5. #5
    Unregistered
    Guest
    Tried it as static as well.

    Replacing CUserinfo3App::WriteCancelled() with CWinApp::WriteCancelled yields the same error.

    making SetRegistryKey & WriteProfileString static in AFXWIN.H removes the error but then I get unresolved symbol errors instead..

    P...

  6. #6
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Tried it as static as well.
    It shouldn't be declared static if it's calling non-static member functions. You can call static member functions with non-static functions but not the other way around. Check the declaration in your header file.

    Also, it's probably not a good idea to mess around with the headers that come with your compiler.

  7. #7
    Unregistered
    Guest
    Just experimenting with the header file to see if it could be fixed..

    I have tryed fixing this problem every way I can can think of without sucess.

    P..

  8. #8
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    What does your CUserinfo3App declaration look like?

  9. #9
    Unregistered
    Guest
    class CUserinfo3App : public CWinApp
    {
    public:
    static void WriteCancelled();

    CUserinfo3App();

  10. #10
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    Remove the static specifier, that's the cause of your problems.

  11. #11
    Unregistered
    Guest
    Tryed that does,nt work. the two registry functions i need are not defined as static in AFXWIN.H.


    P..

  12. #12
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    They don't have to be. What error message do you get when making CUserinfo3App::WriteCancelled() non-static.

  13. #13
    Unregistered
    Guest
    The same C2352 error.

    p.

  14. #14
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    From where in your code are you calling the WriteCancelled() method? Do you have any other static member functions anywhere?

  15. #15
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    error C2352: 'CUserinfo3App::WriteCancelled' : illegal call of non-static member function
    WriteCancelled is a non-static member function. You cannot call it this way: 'CUserinfo3App::WriteCancelled()'. You have to call it on an object like 'myObject.WriteCancelled();'. Only static member functions can be called without an object.
    I'm not sure if the functions you called are static. However, loosing the CUserinfo3App:: specifier could help, as this would work for both versions. Don't ever mess with the compilers files. Leave AFXWIN.H as it is.

    If CancelText is defined elsewhere, this should work:

    PHP Code:
    void CUserinfo3App::WriteCancelled() 

        
    SetRegistryKey("SomeCompany") ; error here 
        WriteProfileString 
    ("LastResult""Operation""Cancelled By User") ;

        
    MessageBoxNULLCancelText"FYI"MB_OK); 

    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MSVC6 Debugger Question
    By Eber Kain in forum C++ Programming
    Replies: 2
    Last Post: 06-24-2004, 07:40 PM
  2. MSVC6 appwizard generated code
    By person877 in forum Windows Programming
    Replies: 1
    Last Post: 07-28-2003, 02:22 PM
  3. Annoying MSVC6 Std bug
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-03-2002, 03:04 PM