Boost.Function compile error
Dear all,
i got a compilation error with vstudio 2010 and Boost.Function:
1) pass functor in constructor
2) pass functor as assignment
3) use Boost.Ref
4) temporary function
void foo()
{
std::identity<int> bla;
boost::function
AMDG On 03/06/2013 03:06 PM, gast128 wrote:
<snip>
void foo() { std::identity<int> bla;
boost::function
fc(bla); boost::function fc2 = bla; boost::function fc(boost::ref(bla)); boost::function (bla); //<-- } first 3 are ok, but the last one vstudio sees this as redefintion of bla of type 'boost::function
. What (and why) do I wrong or should use an explicit cast in the last case?
The last line is treated the same as:
boost::function
thx, I got a simpeler case without Boost.Function: struct Bla { template <typename T> Bla(T t){ t; } }; void Test() { std::identity<int> id; Bla(id); //<- } From curiosity (and not a Boost.Function question anymore), which c++ rule kicks on to treat as a declaration?
thx, I got a simpeler case without Boost.Function:
struct Bla { template <typename T> Bla(T t){ t; } };
void Test() { std::identity<int> id;
Bla(id); //<- }
From curiosity (and not a Boost.Function question anymore), which c++ rule kicks on to treat as a declaration?
Most vexing parse: http://en.wikipedia.org/wiki/Most_vexing_parse
On 3/7/2013 9:00 AM, Igor R wrote:
thx, I got a simpeler case without Boost.Function:
struct Bla { template <typename T> Bla(T t){ t; } };
void Test() { std::identity<int> id;
Bla(id); //<- }
From curiosity (and not a Boost.Function question anymore), which c++ rule kicks on to treat as a declaration?
Most vexing parse: http://en.wikipedia.org/wiki/Most_vexing_parse
Thx, I was aware of Scott Meyers item (stumbled upon that already in the past), but here it can't be seen as a function since 'id' is not a type but a variable. The compiler also see 'id' not as a function but as a variable declaration of 'Bla'. Is that because u can also declare a variable like this: int (i) = 0; and why is that allowed?
Thx, I was aware of Scott Meyers item (stumbled upon that already in the past), but here it can't be seen as a function since 'id' is not a type but a variable. The compiler also see 'id' not as a function but as a variable declaration of 'Bla'. Is that because u can also declare a variable like this:
int (i) = 0;
and why is that allowed?
It's because the compiler threats Bla(id); as: Bla id; as you can see from the errors (MSVC10): error C2371: 'id' : redefinition; different basic types error C2512: 'Bla' : no appropriate default constructor available
On 3/7/2013 10:29 AM, Igor R wrote:
Thx, I was aware of Scott Meyers item (stumbled upon that already in the past), but here it can't be seen as a function since 'id' is not a type but a variable. The compiler also see 'id' not as a function but as a variable declaration of 'Bla'. Is that because u can also declare a variable like this:
int (i) = 0;
and why is that allowed?
It's because the compiler threats Bla(id); as: Bla id; as you can see from the errors (MSVC10): error C2371: 'id' : redefinition; different basic types error C2512: 'Bla' : no appropriate default constructor available
Yes but which (obscure) c++ rule allows this. My day to day c++ knowledge says that () is only used for macro invocations, function declarations, function call's and cast operators and none of them seems to be applicable here.
It's because the compiler threats Bla(id); as: Bla id; as you can see from the errors (MSVC10): error C2371: 'id' : redefinition; different basic types error C2512: 'Bla' : no appropriate default constructor available
Yes but which (obscure) c++ rule allows this. My day to day c++ knowledge says that () is only used for macro invocations, function declarations, function call's and cast operators and none of them seems to be applicable here.
I belive this falls under the paragraph 6.8: "There is an ambiguity in the grammar involving expression-statements and declarations: An expression-statement with a function-style explicit type conversion (5.2.3) as its leftmost subexpression can be indistinguishable from a declaration where the first declarator starts with a (. In those cases the statement is a declaration." While paragraph 5.1 (5) says: "A parenthesized expression is a primary expression whose type and value are identical to those of the enclosed expression. The presence of parentheses does not affect whether the expression is an lvalue. The parenthesized expression can be used in exactly the same contexts as those where the enclosed expression can be used, and with the same meaning, except as otherwise indicated." Try the following :) int (main()) { }
On 3/7/2013 1:00 PM, Igor R wrote:
It's because the compiler threats Bla(id); as: Bla id; as you can see from the errors (MSVC10): error C2371: 'id' : redefinition; different basic types error C2512: 'Bla' : no appropriate default constructor available
Yes but which (obscure) c++ rule allows this. My day to day c++ knowledge says that () is only used for macro invocations, function declarations, function call's and cast operators and none of them seems to be applicable here.
I belive this falls under the paragraph 6.8: "There is an ambiguity in the grammar involving expression-statements and declarations: An expression-statement with a function-style explicit type conversion (5.2.3) as its leftmost subexpression can be indistinguishable from a declaration where the first declarator starts with a (. In those cases the statement is a declaration."
While paragraph 5.1 (5) says: "A parenthesized expression is a primary expression whose type and value are identical to those of the enclosed expression. The presence of parentheses does not affect whether the expression is an lvalue. The parenthesized expression can be used in exactly the same contexts as those where the enclosed expression can be used, and with the same meaning, except as otherwise indicated."
Try the following :)
int (main()) { }
a thx. The standard wording is too cryptic for me but there is an explanation. I should switch to c# :).
participants (3)
-
gast128
-
Igor R
-
Steven Watanabe