I am building a simple package manager for my new Linux distro (check it out as soon as I finish) and have run into a problem. My install() and remove() functions need to access an unspecified amount of Package objects. This is the install function.
void install(int argc, char *argv[]) throw()
{
for (int i = 2; i <= argc; i++)
{
Package p(argv[i]);
p.fetch();
cout << "Package " << p.getRef() << " retrieved succesfully from server.\n";
p.install();
cout << "Package " << p.getRef() << " installed succesfully.\n";
}
}
I suspect this code isn't entirely kosher; this would result in several objects named p which would probably cause a compilation and/or runtime error. What I'm looking for is either a way to change the name p in each iteration of the loop or delete p after one iteration so I will be free to create another object of that name.
pis declared locally inside the loop, every time the loop iterates a new and unique object is created.