c++ - Initialise static data members using lambda function -


i new concept of using lambda functions in c++. aim initialise static data member array of objects using lambda function. below code -

#include <iostream> class b {     public:     b() {std::cout << "b called" <<std::endl;}     b(int y){std::cout << "b int called" <<std::endl;} }; class {     public:     a(){std::cout << "called" << std::endl;}     static b bobj[256]; };  b bobj[256] = [] () {for (int = 0 ; < 256; i++) { bobj[i] = new b(2)}};  int main() {     a; } 

but getting compilation error 'ambiguous overload ‘operator=’ (operand types ‘b’ , ‘b*’)' , others.

how can code lambda function initialise array of objects?

i think see @ least one of problems. definition of bobj array of b objects:

b bobj[256] 

yet trying assign pointer-to-b (by using new):

bobj[i] = new b(2) 

i believe that's cause of error you've shown, ambiguous overload 'operator=' (operand types 'b' , 'b*'). "others" mention can't comment on, because haven't shown them :-)


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -