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

(C++) declaration of 'std::string fil' shadows a parameter

I am trying to make my own compiler(yes) and c++(cpp version of cc) is giving me an error saying: error: declaration of ‘std::string fil’ shadows a parameter.

Code:

#include <iostream>
#include <cstring>
#include <string>

int compile(std::string fil)
{
    std::string cmd = "cc ", fil; // error here
    system(cmd);
    return 0;
}

int main(int argc, char* argv[])
{
   if (argc == 2) {
       std::string tmp = argv[1];
       compile(tmp);
   }
   return 0;
}

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

>Solution :

Not Sure what is your question – but compiler is correct:

<source>:7:30: error: redefinition of 'fil'
    std::string cmd = "cc ", fil; // error here
                             ^
<source>:5:25: note: previous definition is here
int compile(std::string fil)

You have a redefinition of parameter. You should rename one of them.

to add strings

    std::string cmd = "cc " + fil; // error here
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