473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Using boost signals

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
9 3146
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

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
* 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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Leo Kirch | last post by:
Hello XSLT gurus, i've got a rather difficult problem. Some explanations first. theres a signal oriented xml-file - the graphical represantation looks like: | startsignal (signal00) \...
12
by: Charles Law | last post by:
This is a bit of a vague question, but I am just starting on this, and wonder if anyone has ideas of where to start. I have a program that controls some external equipment. It sends messages in...
7
by: sbobrows | last post by:
{Whilst I think much of this is OT for this newsgroup, I think the issue of understanding diagnostics just about gets under the door. -mod} Hi, I'm a C++ newbie trying to use the Boost regex...
0
by: ufnuceda | last post by:
Hello everyone, I was wondering if any of you have some experience with the boost library. I am having trouble compiling code with it. Since boost is being used a lot these days I thought some...
7
by: Adrian Casey | last post by:
I have a multi-threaded python application which uses pexpect to connect to multiple systems concurrently. Each thread within my application is a connection to a remote system. The problem is...
11
by: vippstar | last post by:
What is the purpose of signals and why do they exist in C? thanks in advance
4
by: Man4ish | last post by:
namespace ve/////////////////ve.h { struct VertexProperties { std::size_t index; boost::default_color_type color; }; }...
2
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.