I am a Java developer who is trying to learn C++. The multi-file structure of C++ is strange to me, being a Java developer, spoiled with classes.
I am trying to make a .cpp file that can load other .cpp files similarly to Java classes loading other classes. The way I understand it, is that I have 3 files: main.cpp, filetobeloaded.h, and filetobeloaded.cpp all in the same directory. main.cpp will have a
#include <filetobeloaded.h>
and then filetobeloaded.h will have
#ifndef LOOP_H
#define LOOP_H
void loop_start();
void loop_run();
void loop_init();
#endif /* LOOP_H */
while filetobeloaded.cpp will have
void loop_init(){
//load libraries here
}
void loop_start(){
//this loop runs as long as the user doesn't request the program to close.
//In that case, this function will return and the program will exit.
}
void loop_run(){
//render stuff here, call subroutines
}
Obviously, I am doing something wrong because my compiler tells me that the line
#include <filetobeloaded.h>
is invalid because the file doesn't exist. I have checked and filetobeloaded.h and filetobeloaded.cpp are both in the same directory as main.cpp. I have no idea why it is messing up.
Questions:
Why am I having errors, and how can I fix them?
Is there a better approach to divide my source code to different files than what I am doing?
Can you explain C++ multi-file structure in a way that a Java developer would understand?
I am trying to make a game in C++ with OGL. I am learning C++ vs Java because of speed, fewer memory leaks (I hope), and Steam integration.
I don't have a good book on C++, and I have searched all over the internet... Everyone seems to have a different way of doing this and it is very confusing to me...