Re: forward declaring std::vector. Works, but is it legal and standard compliant?
On 2007-10-27 21:22:29 -0400, Jerry Coffin <jcoffin@taeus.com> said:
In article <1193505682.321253.123810@k79g2000hse.googlegroups.com>,
firkraag07@tlen.pl says...
namespace std {
template <typename T> class allocator;
template <typename T, typename A> class vector;
}
According to section 17.4.3.1.3/1: "Each name declared as an object with
external linkage in a header is reserved to the implementation to
designate that library object with external linkage, both in namespace
std and in the global namespace."
And according to section 17.4.3.1/3: "If the program declares or defines
a name in a context where it is reserved, other than as explicitly
allowed by this clause, the behavior is undefined."
I can't find anything to explicitly allow you to declare std::vector, so
I believe the code has undefined behavior.
And, in particular, standard library implementations are allowed to add
extra template parameters to the standard templates, provided those
parameters have default values. So the forward declaration given above
may be wrong.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]