Re: concatenate variable number of arguments and types to a char
*
On 8/19/2011 3:18 PM, Juha Nieminen wrote:
Leigh Johnston<leigh@i42.co.uk> wrote:
On 19/08/2011 15:31, Juha Nieminen wrote:
Leigh Johnston<leigh@i42.co.uk> wrote:
char* can never point to an array; it can, however, point *into* an
array or one past the end of an array. :)
What's the difference?
(I'd say that since you can delete/free a dynamically allocated array
via a pointer that points to its first element, the pointer in question
*is* pointing to the array.)
Think of it this way: instead of an array of char lets have a vector of
char:
std::vector<char> v(1);
char* p1 =&v[0]; // will compile
char* p2 = v; // will not compile
Clearly p1 is a pointer to a vector element not a pointer to a vector;
p1 points to a vector element; it doesn't point to a vector; critically
pointer decay does not occur as it does with the array case.
I don't really understand. std::vector is not an array, it's a class.
It happens to internally manage an array, but it nevetheless isn't itself
one. For all we know it could be a class that prints the 99 bottles of
beer rhyme.
char* isn't a class (especially not one of type std::vector), nor even
a pointer to one.
Apples and oranges?
Who cares? It is a pointless, time-wasting, discussion about
terminology, and you've started picking on the form in which the
arguments are delivered. Essentially this is "I say tom-AY-to, you say
tom-AH-to". A pointer to an element from a sequence of T is not a
pointer to an array of T because there is already a special type, a
pointer to an array. For 'p' to be a pointer to an array of N T it
would have to be declared T (*p)[N]. But we all say "pointer to an
array of T" because it's easier than the unusual form of "pointer INTO
an array of T", just like we say "a const reference" when we actually
mean "a refernece to a const object".
Now can we drop this?
V
--
I do not respond to top-posted replies, please don't ask