I need ideas/help to create a work around for list initialization in vectors in a class.
I need to create this:
to use this:
The problem I have is that visual studio 2012, (november CTP) won't compile stating "expected a ';' before '}'. Also I am unable to provide in class initializers...Only work around I can think of is creating a constructor?? But the class is titled "Screen".
C++ primer 5th edition gives work arounds for yet to be released features of C++11:
In-class initializers: Explicitly supply the initializer in the constructor initializer
list of every constructor that would otherwise use the in-class initializer.
Doing so is particularly important for members of built-in type.
initializer list<T>: In place of an initializer list<T> parameter,
use a library container or an array.
Here is the code provided by the authors:
Also a separate and long header callsed "Screen".
Quote
Exercise 7.32: Define your own versions of Screen and Window_mgr in which
clear is a member of Window_mgr and a friend of Screen.
clear is a member of Window_mgr and a friend of Screen.
I need to create this:
std::vector<Screen> screens{Screen(24, 80, ' ')};
to use this:
void clear(ScreenIndex);
The problem I have is that visual studio 2012, (november CTP) won't compile stating "expected a ';' before '}'. Also I am unable to provide in class initializers...Only work around I can think of is creating a constructor?? But the class is titled "Screen".
C++ primer 5th edition gives work arounds for yet to be released features of C++11:
In-class initializers: Explicitly supply the initializer in the constructor initializer
list of every constructor that would otherwise use the in-class initializer.
Doing so is particularly important for members of built-in type.
initializer list<T>: In place of an initializer list<T> parameter,
use a library container or an array.
Here is the code provided by the authors:
class Window_mgr { public: // location ID for each screen on the window using ScreenIndex = std::vector<Screen>::size_type; // add a Screen to the window and returns its index ScreenIndex addScreen(const Screen&); // reset the Screen at the given position to all blanks void clear(ScreenIndex); // change dimensions of a given Screen void resize(Screen::pos r, Screen::pos c, ScreenIndex i); private: // Screens this Window_mgr is tracking // by default, a Window_mgr has one standard sized blank Screen std::vector<Screen> screens{Screen(24, 80, ' ')}; };
Also a separate and long header callsed "Screen".