you could use a vector instead of an array
#include
then you can return a vector and not have to worry about every saying pointer!
Dave
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
yea, vector's have a size() function
vector<int> A(5); //declare a vector of length 5
cout << A.size() << endl;
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
> why must C++ be so difficult/strict with this?
Power comes with responsibility.
Scripting languages have expressive power in that you can just write your solution without any care about how it works underneath. But your "I'll just return an array" will entail a hell of a lot of work for the machine, which you just won't see. In a small program, you won't notice, but sooner or later you might think "this is running a bit slow".
C++ (and down through C and to ASM) confront you head on with the problem to make you realise that it isn't quite a free lunch, and you need to start thinking about exactly how it's implemented. Yes it's more work for you, but get it right and you'll see some pretty amazing performance results.
The C++ STL (vector as already mentioned, and a lot of other goodies) go a long way to insulating you from some of the very raw detail. But vanilla arrays in C++ are the same as arrays in C, so you really have to do all the work yourself.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Arrays are useful because they help you understand how things work a little bit, but seem very unpractical to me now that STL has come around and has such a nice vector class.
Dave
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204