Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Error: aggregate value used where an integer was expected

Reply
Thread Tools

Error: aggregate value used where an integer was expected

 
 
Neviton
Guest
Posts: n/a
 
      09-18-2007
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
}

 
Reply With Quote
 
 
 
 
Barry
Guest
Posts: n/a
 
      09-18-2007
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
 
Reply With Quote
 
 
 
 
Barry
Guest
Posts: n/a
 
      09-18-2007
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
 
Reply With Quote
 
Neviton
Guest
Posts: n/a
 
      09-18-2007
Ok impulsive man.
Thank you Barry.
I will try this and give you a feedback.


 
Reply With Quote
 
Neviton
Guest
Posts: n/a
 
      09-18-2007
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

 
Reply With Quote
 
Neviton
Guest
Posts: n/a
 
      09-18-2007
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.

 
Reply With Quote
 
Barry
Guest
Posts: n/a
 
      09-18-2007
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
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      09-18-2007
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


 
Reply With Quote
 
Barry
Guest
Posts: n/a
 
      09-18-2007
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
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      09-18-2007
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
error: aggregate value used where an integer was expected aleksa C Programming 3 02-18-2012 07:09 PM
Cache not working as expected when using list(of integer) mick0987b ASP .Net 2 07-27-2010 08:52 PM
IE object expect & expected identier, string, or integer error on same line mattsniderppl@gmail.com Javascript 3 10-02-2006 09:47 PM
integer int i; *i++ and ++*i have a different integer value after the increment Robben C++ 14 12-27-2005 03:43 AM
J2EE aggregate entity - Value Disassembler Olaf Kittelmann Java 0 12-02-2003 05:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57