Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What does a semicolon after function inside function mean?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading