Error: aggregate value used where an integer was expected

Error: aggregate value used where an integer was expected

Post by Nevito » Wed, 19 Sep 2007 21:26:45


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
}
 
 
 

Error: aggregate value used where an integer was expected

Post by Barr » Wed, 19 Sep 2007 21:31:43


MyFunction is member function, not function

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

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




--
Thanks
Barry

 
 
 

Error: aggregate value used where an integer was expected

Post by Barr » Wed, 19 Sep 2007 21:34:08


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

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



--
Thanks
Barry
 
 
 

Error: aggregate value used where an integer was expected

Post by Nevito » Wed, 19 Sep 2007 22:14:28

Ok impulsive man. :)
Thank you Barry.
I will try this and give you a feedback.
 
 
 

Error: aggregate value used where an integer was expected

Post by Nevito » Thu, 20 Sep 2007 00:30:36

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 find a solution for my
problem.

If you can help me I will really appreciate

Thanks again
 
 
 

Error: aggregate value used where an integer was expected

Post by Nevito » Thu, 20 Sep 2007 00:36:24

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.
 
 
 

Error: aggregate value used where an integer was expected

Post by Barr » Thu, 20 Sep 2007 00:39:20


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
 
 
 

Error: aggregate value used where an integer was expected

Post by Victor Baz » Thu, 20 Sep 2007 00:40:20


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'.


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


Maybe. See FAQ 5.8.


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
 
 
 

Error: aggregate value used where an integer was expected

Post by Barr » Thu, 20 Sep 2007 00:40:52


Post your code to speak the error

--
Thanks
Barry
 
 
 

Error: aggregate value used where an integer was expected

Post by Juha Niemi » Thu, 20 Sep 2007 00:51:10


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.
 
 
 

Error: aggregate value used where an integer was expected

Post by Nevito » Thu, 20 Sep 2007 01:03:22

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;
};
 
 
 

Error: aggregate value used where an integer was expected

Post by Barr » Thu, 20 Sep 2007 01:14:20


Make your member function("OwnerDrawButtonProc") static




--
Thanks
Barry
 
 
 

Error: aggregate value used where an integer was expected

Post by Victor Baz » Thu, 20 Sep 2007 01:17:32


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
 
 
 

Error: aggregate value used where an integer was expected

Post by James Kanz » Thu, 20 Sep 2007 18:00:59


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


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.)


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

James Kanze (GABI Software) email: XXXX@XXXXX.COM
Conseils en informatique orient objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sard, 78210 St.-Cyr-l'ole, France, +33 (0)1 30 23 00 34
 
 
 

Error: aggregate value used where an integer was expected

Post by James Kanz » Thu, 20 Sep 2007 18:04:32


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: XXXX@XXXXX.COM
Conseils en informatique orient objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sard, 78210 St.-Cyr-l'ole, France, +33 (0)1 30 23 00 34