Unrecoverable block scoping error, array of C++ functors -


i'm trying create array of functors @ compile time, so: (complete file):

#include <functional> using namespace std;  function< float( float televation, float pazimuth )> colorfunctions[] = {   []( float televation, float pazimuth ) -> float {     return 2.0f ;   }, } ;  int main() { } 

that works fine. try create local inside functor block, this:

function< float( float televation, float pazimuth )> colorfunctions[] = {   []( float televation, float pazimuth ) -> float {     float v = 2.0f ;     return v ;   }, } ; 

you error 1 error c1506: unrecoverable block scoping error

how can declare locals inside these blocks? doesn't seem work.

i can reproduce on msvc 2010, sp1. vs10 known problems lambdas , scoping. i've tried around lot found nothing beautiful. ugly, ugly workaround have initialization overhead else work intended:

#include <functional> #include <boost/assign/list_of.hpp> #include <vector> using namespace std;  typedef function< float( float televation, float pazimuth )> f3func; vector<f3func const> const colorfunctions = boost::assign::list_of(   f3func([]( float /*televation*/, float /*pazimuth*/ ) -> float {     float v = 2.0f ;     return v ;   }))   ([](float a, float b) -> float {     float somefloat = 3.14f;     return a*b*somefloat;   }) ;  #include <iostream>  int main() {   cout << colorfunctions[1](0.3f,0.4f) << '\n'; } 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -