I have object called Sources, which is member of Singleton S.
std::vector<SRC> Sources;
When I parse arguments in one method, I declare temporal SRC object.
SRC src_temp;
and then I do loop, where I change the temporal instance of SRC type. Because every command line argument can add different option which affects the content of src_temp object. So on the end of the loop there is this
to add the source to vector of sources. Now my question is, how to clear the src_temp object, to be empty or not containing any data which I put there. Because it would make problems when I would continue in the loop without clearing it. The values from previous arguments would be added to the new argument processed and that why I want to clear it.
So in the loop you're doing something to add to your src_temp object each time? If src_temp is declared outside of the loop, you'd have to handle your own way of cleaning out your object to "reset" it back to what you want for the next iteration, we don't know what your src class looks like and it shouldn't matter.
This might not be what you want, I'm not sure, but why not make the temp object inside the for loop so that it cleans itself each iteration?
1 2 3 4 5 6 7 8
std::vector<SRC> Sources;
for (int i = 0; i < 10; i++)
{
SRC src_temp;
//add stuff to temp
//push_back or insert to Sources
}
was processed, there is created new element so now I have two elements in the Sources vector instead one. Something is wrong here because I need that the first circle should update the first element. Can you gimme tip how to do it?
LowestOne means the same thing that Ganado showed: put the src_temp object inside the loop.
every command line argument can add different option which affects the content of src_temp object
Could you do something like this:
1 2 3 4 5 6 7 8 9
SRC partial;
// Copy command line options into partial
for (int i = 0; i < 10; i++)
{
SRC src_temp(partial)
//add other stuff to temp
//push_back or insert to Source
}
SRC Partial1;
TARGET Partial2;
for (std::vector<std::string>::iterator it = raw_args.begin(); it != raw_args.end(); ++it)
{
SRC src_temp(Partial1);
TARGET dest_temp(Partial2);
}
But it does not work. It is the same. Is it the "(1) empty container constructor (default constructor)
Constructs an empty container, with no elements."? They write that when the constructor is empty is sthould create no elements. So why I had and have the elements there. thats mystery for me. Id think that the vector must be initiated so it cannot be empty, but of sure if it could be empty, that would be the best.
It says "(1) empty container constructor (default constructor)
Constructs an empty container, with no elements." but I see there element 0 with filled values as it is initiated.
for (std::vector<std::string>::iterator it = raw_args.begin(); it != raw_args.end(); ++it)
{
SRC src_temp(Partial1);
TARGET dest_temp(Partial2);
i++;
arg=(*it);
std::cout << ": raw: " + arg + "\n";
// Let's suppose that there is -r instead source to define multiple source files
if (i == 1)
S::I().Sources.push_back(SRC());
}
The last line inserts the element which I expected should be on the end. And I think I should use push_back instead of insert.
BTW: Do you know if is it possible to set hotkey for Watch window in Visual Studio 2010? Id like to set my own.