Thread: Compiler Error

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    Compiler Error

    Hi, would anyone be able to help us on this problem. I have got a callback function declared within my class, under protected..

    Code:
    VOID CALLBACK Line(int X, int Y, LPARAM lpData){};
    I haven't put any code within this yet, as i'm just trying to get past this error message from the compiler.

    The callback function relates to
    Code:
    LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, (long)Welcome);
    which is called from within a draw function in my class. I keep getting this following error message related to the 5th parameter within
    LineDDA() function
    [C++ Error] Ass1.cpp(128): E2235 Member function must be called or its address taken
    I've also tried including the get address of operator &, but i get a different error message then.

    However, when i make
    Code:
    VOID CALLBACK Line(int X, int Y, LPARAM lpData){};
    global, i.e. outside of my class it compiles. This callback function has got to be within my class though as it needs to access certain variables. Any help on the problem would be appreciated.
    Be a leader and not a follower.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Can you show the function and how you call it?

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Code:
    #ifndef DrawX
    #define DrawX
    #include <vcl.h>
    
    class DrawX
    {
      protected:
        long WelcomeShown; 
        VOID CALLBACK Line(int X, int Y, LPARAM lpData){};
    
    
      public:
        void Draw(void);
    
    };
    
    void DrawX::Draw()
    {
      WelcomeShown = 0;
      LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, WelcomeShown);
    }
    #endif
    I've also tried including the callback function directly within a c++ app, i.e. within the apps header file, and simply call LineDDA on an event, but i still get the same error message. Yet again, when i make callback global it compiles...???
    Be a leader and not a follower.

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    You have a semicolon at the end of the protected member function definition, you need to remove it.

    If that is not the problem, make the function global to the class as you did before and then give it friend status within the class...


    Code:
    #ifndef _DrawX_
    #define _DrawX_
    #include <vcl.h>
    
    
    VOID CALLBACK Line(int X, int Y, LPARAM lpData){}
    
    
    class DrawX {
    protected:
      long WelcomeShown; 
      friend VOID CALLBACK Line(int, int, LPARAM);
    public:
      void Draw(void);
    };
    
    
    void DrawX::Draw() {
      WelcomeShown = 0;
      LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, WelcomeShown);
    }
    
    
    #endif // _DrawX_
    Watch the preprocessor include guard flag as well, it should not be exactly the same name as the class.
    Last edited by DarkStar; 01-07-2003 at 10:06 PM.

  5. #5
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Right, so because you've made callback a friend of the class, does that mean it will be able to access the other variables declared within that class. i.e. if i have another variable called int temp; within the protected part, will the callback function be able to use that variable?
    Be a leader and not a follower.

  6. #6
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Is there no way to include the callback function within my class so it can access it's variables?
    Be a leader and not a follower.

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Originally posted by subdene
    Right, so because you've made callback a friend of the class, does that mean it will be able to access the other variables declared within that class. i.e. if i have another variable called int temp; within the protected part, will the callback function be able to use that variable?
    Yes. A global function, or a member function of a different class that has friend status inside of this class can access all data members within it.

    Is there no way to include the callback function within my class so it can access it's variables?
    I really feel now that your compile time error was caused by the preprocessor include guard surrounding your class. Make sure that it does not have exactly the same name as your class. Try defining the CALLBACK function inside the DrawX class again with a different include guard like _DRAWX_ instead.
    Last edited by DarkStar; 01-08-2003 at 01:23 PM.

  8. #8
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    I really appreciate your help on this. When i try to access one of the members in the class i get the compiler error: DrawX E2451 Undefined Symbol FormatOk. I've even tried DrawX::FormatOk = true;

    Code:
    #ifndef _DrawX_
    #define _DrawX_
    #include <vcl.h>
    
    
    VOID CALLBACK Line(int X, int Y, LPARAM lpData)
    {
      FormatOk = true;
    }
    
    
    class DrawX {
    protected:
      long WelcomeShown; 
      bool FormatOk;
      friend VOID CALLBACK Line(int, int, LPARAM);
    public:
      void Draw(void);
    };
    
    
    void DrawX::Draw() {
      WelcomeShown = 0;
      LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, WelcomeShown);
    }
    
    
    #endif // _DrawX_
    Be a leader and not a follower.

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Try defining the global after the class declaration...

    Code:
    #ifndef _DrawX_
    #define _DrawX_
    #include <vcl.h>
    
    
    
    class DrawX 
    {
    protected:
      long WelcomeShown; 
      bool FormatOk;
      friend VOID CALLBACK Line(int, int, LPARAM);
    public:
      void Draw(void);
    };
    
    
    
    void DrawX::Draw()
    {
      WelcomeShown = 0;
      LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, WelcomeShown);
    }
    
    
    
    VOID CALLBACK Line(int X, int Y, LPARAM lpData)
    {
      FormatOk = true;
    }
    
    
    
    #endif // _DrawX_
    Compile errors are quite a challenge to figure out.

  10. #10
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Just copied and pasted that, still doesn't work. I give up.
    Be a leader and not a follower.

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Im getting the same compile error too, I will try to figure this one out, it looks difficult. The use of CALLBACK is just not being allowed.

  12. #12
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    ok, thanks for your help.
    Be a leader and not a follower.

  13. #13
    Registered User
    Join Date
    Dec 2001
    Posts
    108
    Try this subdene...

    Code:
    #ifndef _DrawX_
    #define _DrawX_
    #include <vcl.h>
    
    
    
    class DrawX 
    {
    protected:
      long WelcomeShown; 
      bool FormatOk;
      friend VOID CALLBACK Line(int, int, LPARAM);
    public:
      void Draw(void);
    };
    
    // modified global friend...
    VOID CALLBACK Line(int X, int Y, LPARAM lpData)
    {
      DrawX dx; // Here is what was needed
      dx.FormatOk = true;
    }
    
    void DrawX::Draw()
    {
      WelcomeShown = 0;
      LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, WelcomeShown);
    }
    
    
    
    #endif // _DrawX_
    Yes you can give a function external to a class the ability to modify protected and private data members, but you have to create an instance of that class before you can access those data members. STUPID ME, sorry.

    Your program should compile now...
    Last edited by DarkStar; 01-08-2003 at 03:18 PM.

  14. #14
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Darkstar - sorry for the late reply I’ve just been trying to get my class fully working. I took your idea, and just altered it slightly. When the callback functionvcreating an instance of the DrawX class, i had a few problems with the deconstructor. As other class initialize objects, and since these methods weren't being called, it was throwing up an error as these objects were trying to be deleted, but no memory had been allocated to them. Therefore, instead of creating an instance of the class, I passed the actual address of the class by casting the this pointer to a long.

    Code:
    #ifndef _DrawX_
    #define _DrawX_
    #include <vcl.h>
    
    
    
    class DrawX 
    {
    protected:
      long WelcomeShown; 
      bool FormatOk;
      friend VOID CALLBACK Line(int, int, DrawX *);
    public:
      void Draw(void);
    };
    
    // modified global friend...
    VOID CALLBACK Line(int X, int Y, DrawX *Draw)
    {
      Draw.FormatOk = true;
    }
    
    void DrawX::Draw()
    {
      WelcomeShown = 0;
      LineDDA(0, 0, 50, 50, (LINEDDAPROC)Line, (long) this);
    }
    
    
    
    #endif // _DrawX_
    Thanks for your help, it works now.....
    Be a leader and not a follower.

  15. #15
    Registered User
    Join Date
    Dec 2001
    Posts
    108

    Thumbs up

    Cool !

    Good to hear that you got it working.
    Last edited by DarkStar; 01-09-2003 at 08:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  3. error: template with C linkage
    By michaels-r in forum C++ Programming
    Replies: 3
    Last Post: 05-17-2006, 08:11 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM