Question

Take for example we have two arrays called, SourceArray and DestinationArray. In Visual Foxpro, for copying one array into another array, if we have the name of SourceArray as string ( which would be "SourceArray"), we can do the copying using the "&" as following.

fox code:
lcArrayname="SourceArray"

ACOPY(&lcArrayname, DestinationArray)

Who knows how I can do this in the Visual C++? Please help.

Was it helpful?

Solution

C++ does not support "reflection," or the ability to find program objects at run-time (using their name or by traversing the class hierarchy, etc.). In order to copy the contents of one array into another array, you must have both the source and the destination arrays as variables at hand.

You could simulate this ability by creating a data structure keyed by a string. For example, using STL:

map< string, vector<int> > myVectors;

This creates a map that takes a string as key and returns a vector of integers. In this way you can store vectors into the map keyed by a string value and look up the arrays later based on that string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top