+ 2

How is the bug of repeated main in a cpp code fixed ?

I have two files in the same project directory and I keep on getting this error say that permission denied and the project directory has a red like bug on it.. I am using eclipse ide..

5th Jan 2018, 11:35 AM
Otumian Empire
Otumian Empire - avatar
6 Answers
+ 6
The main function specifies the entry point of program execution. You're not supposed to have two main functions. You can post your code here, it'll help to resolve your problems.
5th Jan 2018, 11:39 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
Yeah, so, you obviously can't have two files both containing main and in the same scope. What you can do is to place one of the contents of main into a function, and call it in main. file 1 #include <iostream> #include "file2.cpp" // whatever the filename is using namespace std; int main() { cout << "Hello World."; func(); } file 2 #pragma once #include <iostream> using namespace std; void func() { cout << "Something."; }
5th Jan 2018, 12:32 PM
Hatsy Rei
Hatsy Rei - avatar
+ 5
Post them all, I guess. Can't debug if there's no code.
5th Jan 2018, 11:51 AM
Hatsy Rei
Hatsy Rei - avatar
+ 2
they are two files
5th Jan 2018, 11:40 AM
Otumian Empire
Otumian Empire - avatar
+ 2
first file #include <iostream> using namespace std; into main(){ cout <<"hello world!"; return 0; } second file #include <iostream> using namespace std; int main(){ cout <<"I am getting high and guy"; } yeah.. basically.. this is what I a having...
5th Jan 2018, 11:56 AM
Otumian Empire
Otumian Empire - avatar
+ 2
so if I've more than 2 files, I should call them in the main file?? also. #pragma once, what does it mean
5th Jan 2018, 4:25 PM
Otumian Empire
Otumian Empire - avatar