Hi there,
For example char aa[100] -> char *aa=new char[100];
But for char aa[100][100] how to do this in the same way? char *aa=new char[100][100] isn't good.
I don't understand you. What are you about? Deletion? I didn't forget, I thought that author will do it by hisself.
Some comments about your code:
Question: why there are these useless brackets? Isn't operator = more clear to understand? I think they make the code heavy.
Also it doesn't even compile:
char **aa = new (nothrow) char[100] : result of new char[100] will be char*, but you assign it to char** variable. (maybe it is typo)
for(short i(0); ...) : why short? default array indexes are not short signed int, they are ptrdiff_t!
Why do you use new(std::nothrow)? I think in small examples it is useless.
That is why the green variant (in comments) is better.
It is because a[i] == *(a + i*sizeof base), where base is int* instead of int [100].
If you want the first variant you need to write smth like this:
strcpy( ( (int (*)[100]) a) [i], b[i]);
why there are these useless brackets? Isn't operator = more clear to understand? I think they make the code heavy. (sic)
The outcome is the same. The style falls down to personal preference. It's only one set (2 sets if you count those wrapped around std::nothrow); it's far from heavy. It's not like the compiler cares anyway.
And yes, my code has a typo or two (I'll correct them after this post).
Syuf wrote:
why short? (sic)
Why push 4 bytes onto the stack when I can comfortably push 2 bytes onto the stack with the same outcome?
Syuf wrote:
default array indexes are not short signed int, they are ptrdiff_t! (sic)
True, but I wasn't performing pointer arithmetic.
Syuf wrote:
Why do you use new(std::nothrow)? I think in small examples it is useless. (sic)
It's cleaner than the try ... catch exception handlers.