In C ++ 11, is it definitely wrong to declare a vector of a class that is still an incomplete type of right? I thought I could use incomplete types like pointers, references, return types, or parameter types. A search (1) for an "incomplete type vector" tells me that containers of incomplete types should be an error (I am using g ++ version 4.8.1.). However, the following code compiles on my system:
#ifndef SCREEN
#define SCREEN
#include <string>
using namespace std;
class Screen;
class Window_mgr{
public:
typedef vector<Screen>::size_type screenindex;
void clear(screenindex);
private:
vector<Screen> screens;
};
class Screen{
friend void Window_mgr::clear(screenindex);
public:
typedef string::size_type pos;
Screen() = default;
Screen(pos ht, pos wt): height(ht), width(wt), contents(ht*wt, ' ') { }
Screen(pos ht, pos wt, char c): height(ht), width(wt), contents(ht*wt, c) { }
private:
pos height = 0, width = 0;
pos cursor = 0;
string contents;
};
inline void Window_mgr::clear(screenindex i){
Screen& s = screens[i];
s.contents = string(s.height*s.width, ' ');
}
#endif
, Window_mgr , - . 7.3 ++ Primer , . Screen Window_mgr, clear Window_mgr Screen. , Window_mgr .
IS , ? Window_mgr, , Screen . , - Window_mgr, , ;
class Window_mgr;
class Screen{
friend void Window_mgr::clear(screenindex);
public:
typedef string::size_type pos;
Screen() = default;
Screen(pos ht, pos wt): height(ht), width(wt), contents(ht*wt, ' ') { }
Screen(pos ht, pos wt, char c): height(ht), width(wt), contents(ht*wt, c) { }
private:
pos height = 0, width = 0;
pos cursor = 0;
string contents;
};
class Window_mgr{
public:
typedef vector<Screen>::size_type screenindex;
void clear(screenindex);
private:
vector<Screen> screens;
};
inline void Window_mgr::clear(screenindex i){
Screen& s = screens[i];
s.contents = string(s.height*s.width, ' ');
}
, , memberfunction
class Screen{
friend class Window_mgr;
}
, .