473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

issue on parashift faq section [39.14]

http://www.parashift.com/c++-faq-lit...html#faq-39.14

--------
[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?
AFAIK, this is dependent of the class template specification.

For example, I was able to declare vectors with incomplete types in
more than one compiler.

Diego

Sep 5 '07 #1
3 1614
Diego Martins wrote:
http://www.parashift.com/c++-faq-lit...html#faq-39.14

--------
[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?
It's not explicitly specified one way or the other. However, there is
no requirement in the Standard that a template type argument be a complete
type.
AFAIK, this is dependent of the class template specification.
Yes.
For example, I was able to declare vectors with incomplete types in
more than one compiler.
I believe it all hinges on the meaning of the word "use". Unless you
are instantiating the template, the type argument can be incomplete.
When the instantiation takes place, the type is better be complete;
of course it also depends on the template implementation...

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Sep 5 '07 #2
Diego Martins wrote:
http://www.parashift.com/c++-faq-lit...html#faq-39.14

--------
[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?
In full generality, no. It is possible to design templates that produce
well-defined behavior (even desired behavior) when used with incomplete
types (of course, the type has to be complete at some point). One example
of such a template is tr1::shared_ptr<>.
AFAIK, this is dependent of the class template specification.
Right.
For example, I was able to declare vectors with incomplete types in
more than one compiler.
Now, that goes against the standard. If you use any of the standard
containers with an incomplete type, you have undefined behavior. See
[17.4.3.6, last item].
Best

Kai-Uwe Bux

Sep 6 '07 #3
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

Sep 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Shane | last post by:
Hi, Thanks in advance for the help. I have been to many websites and tried several solutions to my problem, but have fixed part of it. It's time to come humbly to the newsgroups for help :-) ...
30
by: Alf P. Steinbach | last post by:
The C++ FAQ item 29.5 (this seems to be strongly related to C), at <url: http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.5> mentions that <quote> C++ guarantees a char is exactly one...
24
by: Mantorok Redgormor | last post by:
in the standard, function arguments are never referred to as expressions. but we can certainly have expressions in function arguments but not all arguments can qualify as expressions. ...
4
by: Steve | last post by:
I'm currently running into a problem, and I have no idea what to make of it. I have a class with nested clases and static properties that I'm using to store configuration information using a...
2
by: George Durzi | last post by:
I have a dll that I use in several projects, that I placed in the Global Assembly Cache. This dll is references in each of my projects. This Dll is referenced by a type= declaration in my...
8
by: Cardman | last post by:
I am hopeful that someone can quickly solve my image alignment issue when things are just not going right and where my attempts to solve this alignment issue have all failed. First of all take a...
2
by: Rick63 | last post by:
I am using VB .Net 2003 XML namespace to get specified values from an XML document. I have used Stylus Studio 2007 to verify that my XPath query is valid and returns the node/nodes I am looking for....
4
by: Slez via AccessMonster.com | last post by:
I have a recurring corruption issue that appears to be stemming from a Memo field in a table. I have done extensive searching about this topic and have pretty much implemented all possible...
1
by: bumble | last post by:
Hi Everyone I have very little knowledge of Javascript or any other language and have built the basics of my website using Dreamweaver. I have built in extra functions just by trying to follow the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.