Hello all, I realise this is a ridiculously simple question, but please humour me.
If I want to return an array from a function, I see I can dynamically create the array within the function, and return a pointer to the first memory location of that array. But how would I then determine the length of the array returned?
Line 6: (void) is an abomination (according to Stroustrup; I agree).
Line 8: you must provide a size for the array.
Line 9: you cannot copy arrays like that.
Try:
Regarding line 6, and specifying function(void), I do remember reading that somewhere now (Bjarne's site possibly), but why is it an abomination, aren't you simply being clear in the fact that you intended for the function to have no arguments?
I was being a bit of a moron it seems, as cout << ptr; fulfils the problem, and I assume you could also strlen(ptr) if you needed it.
Hate it when I get mind blocks, thanks very much for the tips, very useful!
In C89 void foo() means a "function taking an unspecified number of arguments ..." But since you can't access unspecified arguments, it is pretty much the same as saying "takes no arguments" (usually).
In C99 that is no longer permissible (I think), and the specification prefers you to write void foo(void) to explicitly indicate that the function takes no arguments.
In C++ the standard states that all arguments must be explicitly indicated, either by name or by an elipsis (...), and that just saying 'void' all by itself is stupid (not in those exact words, though :-P). So saying void foo() you are explicitly stating that the function takes no arguments.
/* this comment brought to you by the letter after C */