ok so im a begginner and im trying to figure out how to link my programs together and for one i get a (File directory cannot be found) for the #include <program1.cpp> and secondly after i figured out how to fix that i had to put the whole file location i was getting this
C:\Users\Josh\Desktop\C++\Final.cpp In function 'int main()':
10 5 C:\Users\Josh\Desktop\C++\Final.cpp [Error] redefinition of 'int main()'
5 0 C:\Users\Josh\Desktop\C++\Final.cpp In file included from C:\Users\Josh\Desktop\C++\Final.cpp
6 5 C:\Users\Josh\Desktop\C++\hello1.cpp [Error] 'int main()' previously defined here
13 9 C:\Users\Josh\Desktop\C++\Final.cpp [Error] 'hello1' was not declared in this scope
For your project files, use #include "" as that will first check the same directory or pathname you specified.
Do not directly include other source files. Instead, use header files.
For example:
1 2 3 4 5 6 7
//program1.h
#ifndef PROGRAM1_H //these are known as include guards
#define PROGRAM1_H //They prevent duplication of code
void Program1(); //function prototype
#endif
each program can have only one main function, which is the entry point for execution of program, looks like you are trying to include other programs with main functions:
you cannot do this, if u want to invoke some methods defined in some other file, try creating hpp files, in which u can define ur functions, include those hpp files in ur program, google hpp file creation for more details.
#include <iostream>
usingnamespace std;
#include "second.h" // pp if you like
int main(void)
{
secondfunc();
second_value=3;
}
second.h:
1 2 3
/* second.h */
externint second_value; // declare second_value as extern (actual declaration of it is in the .cpp)
int secondfunc(void); // prototype for secondfunc
second.cpp:
1 2 3 4 5 6 7 8 9
#include <iostream>
#include "second.h"
int second_value=0;
int secondfunc(void)
{
cout<<"This is secondfunc()"<< endln;
}