Error: aggregate value used where an integer was expected

Discussion in 'C++' started by Neviton, Sep 18, 2007.

  1. Neviton

    Neviton Guest

    Help with this error ! Please !
    The code below is simplified, because I'm trying to solve this error.

    ....MyClass.cpp In member function `void MyClass::Initialize()':
    ....MyClass.cpp aggregate value used where an integer was expected
    ....Makefile.win [Build Error] [MyClass.o] Error 1

    The code:

    /* MyClass.h *****************/
    class MyClass
    {
    public:
    void Initialize();
    void MyFunction();
    };

    /* MyClass.cpp **************/
    #include "MyClass.h"
    void MyClass::Initialize()
    {
    long address = (long)MyFunction; //this line rises the error
    }

    void MyClass::MyFunction()
    {
    //empty
    }
    Neviton, Sep 18, 2007
    #1
    1. Advertising

  2. Neviton

    Barry Guest

    Neviton wrote:
    > Help with this error ! Please !
    > The code below is simplified, because I'm trying to solve this error.
    >
    > ...MyClass.cpp In member function `void MyClass::Initialize()':
    > ...MyClass.cpp aggregate value used where an integer was expected
    > ...Makefile.win [Build Error] [MyClass.o] Error 1
    >
    > The code:
    >
    > /* MyClass.h *****************/
    > class MyClass
    > {
    > public:
    > void Initialize();
    > void MyFunction();
    > };
    >
    > /* MyClass.cpp **************/
    > #include "MyClass.h"
    > void MyClass::Initialize()
    > {
    > long address = (long)MyFunction; //this line rises the error


    MyFunction is member function, not function

    void MyClass::*pmf = &MyClass::MyFunction;

    Moreover, casting a function pointer to other type is meaningless.


    > }
    >
    > void MyClass::MyFunction()
    > {
    > //empty
    > }
    >



    --
    Thanks
    Barry
    Barry, Sep 18, 2007
    #2
    1. Advertising

  3. Neviton

    Barry Guest

    Barry wrote:
    > Neviton wrote:
    >> Help with this error ! Please !
    >> The code below is simplified, because I'm trying to solve this error.
    >>
    >> ...MyClass.cpp In member function `void MyClass::Initialize()':
    >> ...MyClass.cpp aggregate value used where an integer was expected
    >> ...Makefile.win [Build Error] [MyClass.o] Error 1
    >>
    >> The code:
    >>
    >> /* MyClass.h *****************/
    >> class MyClass
    >> {
    >> public:
    >> void Initialize();
    >> void MyFunction();
    >> };
    >>
    >> /* MyClass.cpp **************/
    >> #include "MyClass.h"
    >> void MyClass::Initialize()
    >> {
    >> long address = (long)MyFunction; //this line rises the error

    >
    > MyFunction is member function, not function
    >
    > void MyClass::*pmf = &MyClass::MyFunction;


    Sorry, what a impulsive man I am! deal too much with pointer to member
    recently :)

    void (MyClass::*pmf)() = &MyClass::MyFunction;

    >
    > Moreover, casting a function pointer to other type is meaningless.
    >
    >
    >> }
    >>
    >> void MyClass::MyFunction()
    >> {
    >> //empty
    >> }
    >>

    >
    >



    --
    Thanks
    Barry
    Barry, Sep 18, 2007
    #3
  4. Neviton

    Neviton Guest

    Ok impulsive man. :)
    Thank you Barry.
    I will try this and give you a feedback.
    Neviton, Sep 18, 2007
    #4
  5. Neviton

    Neviton Guest

    How can I get the address of the function and save in a long variable.

    My deal is use this WIN32 function that must receive the address of
    function.

    I know, I know
    This is not a WIN32 Group but
    I think my problem is with C++ instead WIN32.

    I am wasting time for a few days and I can´t find a solution for my
    problem.

    If you can help me I will really appreciate

    Thanks again
    Neviton, Sep 18, 2007
    #5
  6. Neviton

    Neviton Guest

    When I try this in the main application class everything works fine.
    The "aggregate value used where an integer was expected" error just
    happen when I put the code in a Class.
    Neviton, Sep 18, 2007
    #6
  7. Neviton

    Barry Guest

    Neviton wrote:
    > How can I get the address of the function and save in a long variable.
    >
    > My deal is use this WIN32 function that must receive the address of
    > function.
    >
    > I know, I know
    > This is not a WIN32 Group but
    > I think my problem is with C++ instead WIN32.
    >
    > I am wasting time for a few days and I can´t find a solution for my
    > problem.
    >
    > If you can help me I will really appreciate
    >


    If you have various kind of function which have different parameter
    list, then you have to borrow Boost.Function, as my experience, I use
    boost::function0<void> as wrapper, then bind any type of functor, free
    function and member function into this wrapper.

    If the parameter list is fixed, then you can write your own wrapper,
    refer to 'mem_fun', 'bind2nd' ... in STL.


    --
    Thanks
    Barry
    Barry, Sep 18, 2007
    #7
  8. Neviton wrote:
    > How can I get the address of the function and save in a long variable.


    If that's a question, the answer is to use 'reinterpret_cast', but do
    not rely on the pointer to fit into a 'long'. You may need to have
    something different there, like 'uint64_t'.

    > My deal is use this WIN32 function that must receive the address of
    > function.


    <shrug> OK. Where does the 'long' come in?

    > I know, I know
    > This is not a WIN32 Group but
    > I think my problem is with C++ instead WIN32.


    Maybe. See FAQ 5.8.

    > I am wasting time for a few days and I can´t find a solution for my
    > problem.


    Neither can we unless we actually see some code.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Sep 18, 2007
    #8
  9. Neviton

    Barry Guest

    Neviton wrote:
    > When I try this in the main application class everything works fine.
    > The "aggregate value used where an integer was expected" error just
    > happen when I put the code in a Class.
    >

    Post your code to speak the error

    --
    Thanks
    Barry
    Barry, Sep 18, 2007
    #9
  10. Neviton wrote:
    > How can I get the address of the function and save in a long variable.
    >
    > My deal is use this WIN32 function that must receive the address of
    > function.


    I don't even want to know why windows would want a function pointer as
    a long (although having seen the Windows API I'm not even surprised
    about anything anymore), but if if expects a pointer to a *function* and
    you are giving a pointer to a *method* it won't work (at least if that
    windows function tries to call your function through the pointer). A
    method is not a regular function.
    Juha Nieminen, Sep 18, 2007
    #10
  11. Neviton

    Neviton Guest

    Here is the code:

    I'm getting this error
    .... Button.cpp In member function `void Button::Create(HWND__*,
    char*)':
    .... Button.cpp aggregate value used where an integer was expected

    /* Button.cpp ****************/
    #include "Button.h"
    void Button::Create(HWND hWindow, char * text)
    {
    Button::hWindow = hWindow;
    handle = CreateWindow("Button", text, WS_CHILD | WS_VISIBLE, 10,
    10, 100, 20, hWindow, (HMENU)0, NULL, NULL);
    mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC,
    (LONG) OwnerDrawButtonProc); // THE ERROR OCCUR HERE

    }

    HWND Button::Handle()
    {
    return handle;
    }

    LRESULT CALLBACK Button::OwnerDrawButtonProc(HWND hWnd, UINT uMsg,
    WPARAM wParam, LPARAM lParam)
    {
    switch (uMsg)
    {
    case WM_PAINT:
    return TRUE;
    }
    return CallWindowProc(mainWindowProc, hWnd, uMsg, wParam, lParam);
    }


    /* Button.h ******************/
    #include <windows.h>
    class Button
    {
    public:
    void Create(HWND hWindow, char * text);
    HWND Handle();
    private:
    LRESULT CALLBACK OwnerDrawButtonProc(HWND hWnd, UINT uMsg,
    WPARAM wParam, LPARAM lParam);
    HWND hWindow;
    HWND handle;
    WNDPROC mainWindowProc;
    };
    Neviton, Sep 18, 2007
    #11
  12. Neviton

    Barry Guest

    Neviton wrote:
    > Here is the code:
    >
    > I'm getting this error
    > ... Button.cpp In member function `void Button::Create(HWND__*,
    > char*)':
    > ... Button.cpp aggregate value used where an integer was expected
    >
    > /* Button.cpp ****************/
    > #include "Button.h"
    > void Button::Create(HWND hWindow, char * text)
    > {
    > Button::hWindow = hWindow;
    > handle = CreateWindow("Button", text, WS_CHILD | WS_VISIBLE, 10,
    > 10, 100, 20, hWindow, (HMENU)0, NULL, NULL);
    > mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC,
    > (LONG) OwnerDrawButtonProc); // THE ERROR OCCUR HERE


    Make your member function("OwnerDrawButtonProc") static

    >
    > }
    >




    --
    Thanks
    Barry
    Barry, Sep 18, 2007
    #12
  13. Neviton wrote:
    > Here is the code:
    >
    > I'm getting this error
    > ... Button.cpp In member function `void Button::Create(HWND__*,
    > char*)':
    > ... Button.cpp aggregate value used where an integer was expected
    >
    > /* Button.cpp ****************/
    > #include "Button.h"
    > void Button::Create(HWND hWindow, char * text)
    > {
    > Button::hWindow = hWindow;
    > handle = CreateWindow("Button", text, WS_CHILD | WS_VISIBLE, 10,
    > 10, 100, 20, hWindow, (HMENU)0, NULL, NULL);
    > mainWindowProc = (WNDPROC) SetWindowLong(handle, GWL_WNDPROC,
    > (LONG) OwnerDrawButtonProc); // THE ERROR OCCUR HERE


    Does it work if you simply pass 0?

    >
    > }


    Well, since we don't know what 'SegWindowLong' does, and what it
    expects as its third argument, it's hard to tell what the solution
    would be. However, it might help you to define 'OwnerDrawButtonProc'
    as non-member, perhaps. Are you sure it's a static function in
    your 'Button' class? If it isn't, you probably can't declare it
    "CALLBACK" because callbacks usually don't have the instance of
    the class to be called for. Search the FAQ for "callback".

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Sep 18, 2007
    #13
  14. Neviton

    James Kanze Guest

    On Sep 18, 5:30 pm, Neviton <> wrote:
    > How can I get the address of the function and save in a long variable.


    If it's a non-static member function, you can't.

    > My deal is use this WIN32 function that must receive the address of
    > function.


    What is the signature of the target function? I'm willing to
    bet that it's something like:

    void f( void (*)( void* ), void* ) ;

    or even (more likely):

    extern "C" void f( void (*)( void* ), void* ) ;

    In neither case is a non-static member function acceptable, and
    in the second case, even a static member function is not
    acceptable.

    If the pointer to the function is in fact passed using some data
    type, e.g. a uint32_t, then you are skating on thin ice. You
    must know how the function will be called. (`extern "C++"' or
    `extern "C"', according to the standard, but VC++ has some
    additional options), and only convert the address of a function
    which can be called in that matter. In this case, the compiler
    cannot help with the verifications. (And of course, a member
    function is called in a far different manner than a non-member
    function. The two are not compatible in any way.)

    > I know, I know This is not a WIN32 Group but I think my
    > problem is with C++ instead WIN32.


    A bit of both. There are certainly C++ problems involved (and
    Posix has similar problems).

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Sep 19, 2007
    #14
  15. Neviton

    James Kanze Guest

    On Sep 18, 5:51 pm, Juha Nieminen <> wrote:
    > Neviton wrote:
    > > How can I get the address of the function and save in a long variable.


    > > My deal is use this WIN32 function that must receive the address of
    > > function.


    > I don't even want to know why windows would want a function pointer as
    > a long (although having seen the Windows API I'm not even surprised
    > about anything anymore), but if if expects a pointer to a *function* and
    > you are giving a pointer to a *method* it won't work (at least if that
    > windows function tries to call your function through the pointer). A
    > method is not a regular function.


    For various reasons, OS's often have functions which violate
    type safety. Regretfully, Windows isn't alone in this. (The
    worst I've seen is dlsym, under Unix.)

    And the problem isn't just (non-static) member vs. regular
    function. Windows (or at least VC++) supports several different
    call conventions; unless the function has the expected call
    conventions, there's going to be problems at runtime.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
    James Kanze, Sep 19, 2007
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Olaf Kittelmann

    J2EE aggregate entity - Value Disassembler

    Olaf Kittelmann, Dec 2, 2003, in forum: Java
    Replies:
    0
    Views:
    374
    Olaf Kittelmann
    Dec 2, 2003
  2. Charles Jamieson

    non-aggregate error

    Charles Jamieson, Jul 13, 2004, in forum: C++
    Replies:
    6
    Views:
    480
    Old Wolf
    Jul 14, 2004
  3. koperenkogel
    Replies:
    3
    Views:
    2,689
    =?ISO-8859-1?Q?Ney_Andr=E9_de_Mello_Zunino?=
    Mar 24, 2005
  4. aleksa
    Replies:
    3
    Views:
    1,577
    aleksa
    Feb 18, 2012
  5. Replies:
    3
    Views:
    116
Loading...

Share This Page