I saw an answer for a c++ challenge that had you copy a certain part of a string x times.
std::string repeatString(int xTimes)
{
repeatString;(3); //What's happening here?
}
He seemed to have solved the challenge with this code and I’m guessing he solved it the wrong way but I’m still unsure what’s happening.
original challenge:
https://edabit.com/challenge/vxpP4nnDhRr2Yc3Lo
original answer by Marcus_2008
>Solution :
repeatString; is an expression that does nothing useful. Same for (3);. Its the same as 3; and does literally nothing. After removing that unnecessary fluff, the function is
std::string repeatString(int) {
//What's happening here?
// - nothing at all
}
And this, not only does it not repeat a string, but it invokes undefined behavior when called, because it is declared to return a std::string but does not.
Even changing the line to repeatString(3); would leave us with the same issue while return repeatString(3); would result in infinite recursion.
It is not possible that this code solves the task. You must have misunderstood something, or the real code looks different.