Functions in separate files

There are two ways to add functions to a project,
(1) add the function declaration and the function definition in main() or
(2) or put function declaration and function definition into separate files (.cpp .hpp).

Now, it seems to me that you can’t mix both in CLion. Is that so?

Because I moved some function from main() to separate files, but left others in main(). Now I get an error if a function that is in a separate files wants to access a function in main(). Therefore I assume I have to move ALL functions to separate files. Or is there another trick, or a way to get that working?


I’m pretty sure you can have mixed ways: you can have some functions in separate files and other in main. Perhaps it’s due to the correct uses of the includes.
Could you post the exact error you receive? Or better, you can share your files on and paste the gist link here.

Thank you. Your response gave me an idea. I tried it out. It didn’t quite work. But I started to dig and learn in more detail about header files and source files and how they interrelate. I’m still working on it, but in the end I think I will be much more competent to find my way around and handle these program files. Thanks so far for the kick start :slightly_smiling_face:

I do not have CLION, so I may be off, but that sounds to me all the functions that want to talk to each other need to be inside the same file.