On Sep 5, 9:19 pm, Diego Martins <jose.di...@gmail.comwrote:
http://www.parashift.com/c++-faq-lit...sues.html#faq-...
--------
[39.14] Why can't I put a forward-declared class in a std::vector<>?
...
Just remember this: Whenever you use a class as a template parameter,
the declaration of that class must be complete and not simply forward
declared.
--------
is this endorsed by the standard?
I'd need more context to be sure. In general, the standard only
requires a complete definition where something is instantiated
in the template which requires a complete definition. And it is
very conservative with regards to what may be instantiated. The
question, however, involves std::vector, and the standard says
very explicitly that instantiating any part of any of the
standard templates over an incomplete type is undefined
behavior.
AFAIK, this is dependent of the class template specification.
It is dependent on the specification. The specification for the
templates in the standard says that the type must be complete,
and that it is undefined behavior otherwise.
For example, I was able to declare vectors with incomplete
types in more than one compiler.
It's undefined behavior. It might work. Sometimes. (It will
fail to compile with recent versions of g++, at least if the
usual options are given.)
--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34