I am trying to figure out how to create object dynamically. I have a custom class which stores information from data files. I wrote the program to deal with only one data file at a time when I first wrote it. Now I want it to deal with multiple data files, the number of which will be subject to change. I have looked up some solutions to this online and played around a bit but I have not yet been able to find something that seemed to me to match my needs. I was wondering if someone could point me in the direction of something that could help me with this.
Could you please be more specific? :) you can use new operator but not sure how exactly you want it.
1 2 3 4 5 6 7 8 9 10 11
class a
{
};
int main()
{
a* ao=new a; //calls a no argument constructor
a* ao1=new a(/*values*/) //calls one or more argument constructor.
a* ao2=new a[5]; //calls no argument constructor and initializes an array of objects.
}
I am doing data analysis on several files all of the same format. I will be processing large numbers of these files in batches which vary in size from a few files to 20 or more. I need to compare the results of these files as well. I am trying to eliminate the need to do more IO operations with files in order to maximize performance.
I want to be able to create a new object for each file. Each object should have a different name and should be able to be used throughout the program to manipulate data from that file as well as data across files. In a sense I want to be able to create one object per file and then loop through a property of each object in order to compare it. I know how to create new objects once I have a custom class created but I do not know how to write a program that dynamically creates n number of objects based on n number of files and assigns to each of those objects a name that can be referred to throughout the program.