+ 3

How to create function in separate files

Ok now we have learned we can create class in separate file but what about creating function in separate file. Like I mean mentioned the header file then use all the user defined function in any cpp file

14th May 2019, 8:43 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
11 Antworten
+ 9
Don't forget to include your custom header files in your main cpp file and link all cpp files in order to compile the whole thing
15th May 2019, 5:53 AM
Anna
Anna - avatar
+ 6
You need the main function for a program.
15th May 2019, 12:15 AM
Sonic
Sonic - avatar
+ 3
The same way, you do it with classes: .h void func(int); .cpp #include "a.h" void func(int a) { std::cout << a; }
14th May 2019, 8:49 PM
Paul
+ 3
Thanks
14th May 2019, 8:53 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 3
Ok I just tried but getting error in the cpp Undefined reference to winmain
14th May 2019, 8:58 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 3
Undefined reference to winmain usually means you don't have a main function.
14th May 2019, 9:21 PM
Dennis
Dennis - avatar
+ 3
So how can we create function in separate files
14th May 2019, 11:24 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 2
I don't develop much using windows but that's most likely because of a missing windows dependency
14th May 2019, 9:00 PM
Paul
+ 2
I don't understand your point bro
14th May 2019, 9:01 PM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 2
Any example I can get bro
15th May 2019, 12:16 AM
Arslan Iftikhar
Arslan Iftikhar - avatar
+ 2
Thanks for help Anna I got it. I was not creating project I was doing that on single source files thanks
15th May 2019, 10:36 AM
Arslan Iftikhar
Arslan Iftikhar - avatar