By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,225 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

Using boost signals

P: n/a
g++ wont let me compile boost signals, not even the example that comes
in the documentation. I have the libboost_signals.a binary but im not
sure if im using it correctly. Here is the code

#include "boost/signal.hpp"
#include <iostream>

int main() {
struct HelloWorld
{
void operator()() const {
std::cout << "Hello, World!" << std::endl;
}
};

boost::signal<void()sig;
HelloWorld hello;

sig.connect(hello());

sig();
return 0;#include "boost/signal.hpp"
}

g++ complains about the expression void being used in an invalid way.

I dont know what i am doing wrong
Thanks

Aug 6 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
atomik.fungus wrote:
boost::signal<void()sig;
g++ complains about the expression void being used in an invalid way.
At a guess, take out the ()?

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 6 '06 #2

P: n/a

Phlip ha escrito:
At a guess, take out the ()?
Doing so gives even more errors: I also tried the portable syntax with
the same results

Taken out the () gives:
there is no type called 'result_type' in 'struct
boost::detail::function_traits_helper<void*>
template argument 2 is invalid

Aug 6 '06 #3

P: n/a
* at***********@gmail.com:
g++ wont let me compile boost signals, not even the example that comes
in the documentation. I have the libboost_signals.a binary but im not
sure if im using it correctly. Here is the code

#include "boost/signal.hpp"
#include <iostream>
I'd prefer to put the Boost libraries in the default library search path
for the compiler, and writing

#include <boost/signal.hpp>

int main() {
struct HelloWorld
{
void operator()() const {
std::cout << "Hello, World!" << std::endl;
}
};
Class HelloWorld probably needs to be declared outside 'main'. Reason:
you can't instantiate a template on a local class, and most likely this
class will be used that way.

boost::signal<void()sig;
Note that the documentation lists an alternate form for
not-very-up-to-date compilers; however, a recent version of g++ should
be OK.

HelloWorld hello;

sig.connect(hello());
Probably this should be

sig.connect( hello );

sig();
return 0;#include "boost/signal.hpp"
Uh...
}

g++ complains about the expression void being used in an invalid way.

I dont know what i am doing wrong
The fixes above may not be enough. Just to make sure I plugged the code
into Visual Studio, but it complains about not finding the library. And
I just don't feel like delving into those tool issues right now, sorry.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Aug 6 '06 #4

P: n/a
at***********@gmail.com wrote:
sig.connect(hello());
The type of "hello()" is void. You're attempting to pass a void.

You want
sig.connect(hello);
Aug 6 '06 #5

P: n/a
Class HelloWorld probably needs to be declared outside 'main'. Reason:
you can't instantiate a template on a local class, and most likely this
class will be used that way.
HelloWorld hello;

sig.connect(hello());

Probably this should be

sig.connect( hello );
Thanks for the help, i understand the need for HelloWorld to be outside
main, but why do I have to change hello() for hello, isnt the idea of
using operator() being able to give functions wrapped in classes the
feel of normal functions?

Aug 6 '06 #6

P: n/a
atomik.fungus wrote:
> sig.connect( hello );

Thanks for the help, i understand the need for HelloWorld to be outside
main, but why do I have to change hello() for hello, isnt the idea of
using operator() being able to give functions wrapped in classes the
feel of normal functions?
You are passing the object hello into the function connect, so that inside
it can call hello().

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
Aug 6 '06 #7

P: n/a
Phlip wrote:
atomik.fungus wrote:
> boost::signal<void()sig;
>g++ complains about the expression void being used in an invalid way.

At a guess, take out the ()?
Nope, they are required there. It's the type of the function.

He has an extra set later on though.
Aug 6 '06 #8

P: n/a
at***********@gmail.com wrote:
>Class HelloWorld probably needs to be declared outside 'main'. Reason:
you can't instantiate a template on a local class, and most likely this
class will be used that way.
>> HelloWorld hello;

sig.connect(hello());
Probably this should be

sig.connect( hello );

Thanks for the help, i understand the need for HelloWorld to be outside
main, but why do I have to change hello() for hello, isnt the idea of
using operator() being able to give functions wrapped in classes the
feel of normal functions?
Yes, but when you say hello(), you are calling the function and
passing it's return value (in this case void) to connect.

Connect whats an instance of the class.

I think you are confusing an local instance of the class (hello)
with a default initialized temporary (HelloWorld()).

Aug 6 '06 #9

P: n/a
On 6 Aug 2006 06:13:03 -0700, at***********@gmail.com wrote:
>g++ wont let me compile boost signals, not even the example that comes
in the documentation. I have the libboost_signals.a binary but im not
sure if im using it correctly.
Try this: http://www.codeproject.com/cpp/FastDelegate.asp
Aug 6 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.