Re: compile error about auto_ptr
- From: "Alf P. Steinbach" <alfps@xxxxxxxx>
- Date: Sun, 24 Feb 2008 09:07:14 +0100
* George:
Thanks Alf,
1.
Informally, that you can construct a copy of any object of the type.
Including an rvalue or const lvalue type, right?
Yes, if you mean construct "from" an rvalue or const lvalue.
2.
Formally defined by §20.1.3/1, which adds the requirement of an available address operator that provides the address.
Why address operator is required?
This question, about the rationale of the standard, would be better asked in [comp.std.c++].
Except that group is down. For good, it seems. In earlier private communication with one of the moderators there was some hinting that perhaps [comp.std.c++] would be converted to unmoderated, like [comp.std.c], but it seems that precisely nothing is actually happening. Since this is a Microsoft forum I might mention that it seems that the active (or rather, apparently, inactive!) [comp.std.c++] moderators all work at Google. So there!
Anyways, one possible reason is to facilitate in-place construction of elements for e.g. std::vector, with the Evil(TM) practice (as found e.g. in the default standard allocator) of typed storage.
In my experience, copy constructor does not utilize address operator.
Copy constructor is /necessary/ for copy construction. It's not on its own /sufficient/, in all contexts, for actually constructing a copy. One example given above (you need access to the storage in which to construct a copy).
3.
The notion of "copy constructor" in the standard is unfortunately neither intuitive nor very practical (in particular, a templated constructor does not qualify as a formal copy constructor). It's just an example of adopting a special case descriptive term as a formal name for a slightly more general category. Where it doesn't always make sense as a descriptive term -- only as a formal name.
Confused after reading a couple of time, especially about term "formal name" and "descriptive term".
What do you mean "It's just an example of adopting a special case descriptive term as a formal name for a slightly more general category."?
I think I'll leave you to figure that out yourself... ;-)
An example from some other domain might help, though.
In Norwegian law, the descriptive term "varebil" ("vare": goods, "bil": car, a car used to transport goods, essentially a van) is given a very strict definition as a formal term, with the result that some ordinary cars have sub-optimal designs in order to be formally classified as "varebil" -- or not -- so as to avoid extra taxes. This may or may not be a true story. But the essence is that a car that nobody in their right mind would describe as a "varebil" nevertheless is formally classified as that (then using it as formal term), and vice versa.
4.
The error messages direct you to std::auto_ptr and std::vector<std::auto_ptr>>. Elimination of what it could not be leaves you with what it could be. A bit of knowledge of the requirements of the standard library's container classes helps, and for this, a good C++ textbook (plus perhaps a copy of the standard) is key.
I think you mean from the compile error message, there is no direct information about the copy constructor which accepts const reference as input parameter is missing?
(it just tell you one type of required copy constructor is missing, and we need knowledge about container to find which copy constructor is missing?)
Essentially, yes.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
.
- Follow-Ups:
- Re: compile error about auto_ptr
- From: George
- Re: compile error about auto_ptr
- References:
- compile error about auto_ptr
- From: George
- Re: compile error about auto_ptr
- From: Alf P. Steinbach
- Re: compile error about auto_ptr
- From: Alf P. Steinbach
- Re: compile error about auto_ptr
- From: George
- compile error about auto_ptr
- Prev by Date: Help with Hooks and EnumProcesses
- Next by Date: FindWindow Headache
- Previous by thread: Re: compile error about auto_ptr
- Next by thread: Re: compile error about auto_ptr
- Index(es):
Relevant Pages
|