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;
}
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