Boost logo

Boost :

From: Daniel Spangenberg (dsp_at_[hidden])
Date: 2003-10-02 03:01:49


Chris Byrne schrieb:

> On Thu, 02 Oct 2003 00:14:34 -0400
> Stefan Seefeld <seefeld_at_[hidden]> wrote:
>
> > > GCC 3.2.2:
> > > boostthreads.cpp: In function `int main()':
> > > boostthreads.cpp:45: request for member `join' in `thrd2(MyThread)', which is of non-aggregate type `boost::thread ()(MyThread)
> >
> > ...it interprets the above declaration of 'thrd2' as the declaration
> > of a function taking a 'MyThread' argument and returning a 'boost::thread'.
> >
> > No wonder no thread is created !
> >
> > As you discovered, changing the expression not to use an 'unnamed > temporary' will solve the problem. The other errors you report all
> > seem to be of the same kind. Optimization is never the issue, just a
> > misunderstanding of the expression.
>
> oh right, but...
>
> if this is a function declaration:
> boost::thread thrd2(MyThread(idx))
>
> then why are neither of these?
> boost::thread thrd2(MyThread(1))
> boost::thread thrd2(MyThread((int)idx))

They can not be valid function declarations, because
- 1 is not a valid identifier for a function parameter (But idx is one)
- Casting the function parameter is not valid (Be aware, that this time we have no further
parameter type declaration!).

The rule is: "Anything what can be a declaration is a declaration!"

> Futher more, how can an instantiated variable idx actually be used in a function declaration?

Function parameter identifier in function declarations never interact with other valid names outside
the scope of the function declaration, because they are local to scope of the function prototype.
Otherwise you would change the meaning of function declarations in situations where you introduce
further names.

Ex.:

int x;

void foo(double x); // This x does not give any name clashing with the outer x!

// Names of foo's parameters are no longer available here!

void bar()
{
  x = 3.0; // Does not assign a double litaral to foo's x!
}

Hope that helps,

Daniel Spangenberg


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk