Well, obviously, this kind of thing won't work:
But as long as you keep the type information through proper references, it will work.Code:#include <iostream> template<size_t N> void foo(int (&bar)[N]) { std::cout << N << std::endl; } int main() { int bla[50]; int* r = bla; foo(*r); }
Though, I am not entirely sure of what scenario you had in mind.
>Well... I use C Style arrays only in analogy to pointers...
>>What do you mean?
Foo* foo = new Foo[n];
vector as well as most STL containers (except array in fact) use the heap.
C++ does not manage memory in the sense that what you new, you must delete (though there are tools that help you do that, such as smart pointers).
If you use containers, they manage that memory for you. There is almost never any need to allocate a container on the heap.
When there is?
Suppose...
As of my current project: I have a class that privately stores a std::vector of std::map `s ...of which 3 Global Objects are declared to be used from all the other modules somewhat like environment variables.
Whenever I am adding a map to one of those, I'm allocating ..and then passing its value to the relevant function to 'push' it.
I'm not sure.. but would it work if I just create a map and pass it ?