Hello I am a cpp beginner. I've been writing in java and mostly php for my work so I know a good deal about programming languages in general but I'm having trouble doing simple things in cpp and not having much luck with google.
In java you could create multiple files in the same folder and call classes and methods from those files so I'm a bit spoiled. I'm trying to make a simple socket program where my main classes makes socket connections. So I've got a class called ServerSocket that resides in the same folder as my main.exe file. I'm trying to include this file but I don't know what I'm doing.
Do I need the absolute path?
(if so)
Is there a way to make it dynamic incase I move these files around?
Would I be including an exe or a cpp file? I'm getting a compile error so I don't know what the program wants to read. If I take out that include the error shows-
8 ~~:\~~\~~\~~\~~\main.cpp `ServerSocket' undeclared (first use this function)
Thanks for your help! Looking forward to learning cpp!
Edit: Solution
Ok. Been messing with it and found a solution. I had to change the include to ServerSocket.h and use absolute path.
In c++ you have to have all of your files in the same project, not the same folder. You can't directly include an exe. However you can split it up into different .cpp and .h files.
Don't include .cpp files either, when you include files, only include .h (header) files, they have your forward declarations or prototypes.
You can also make the ServerSocket in the same file as your main- this isn't Java (and thank heavens, I hated that whole one class/ file thing) so it's pretty flexible =]
I think I edited my original while you were posting. Thanks for the clarifications. So I will be required to use absolute paths then? Or is there a trick to it?
In c++ if you're including your own header files and cpp files (depending on the IDE / editor) you just add both to your project and include your header file like this:
#include "headerfilenoticethequotes.h"
If you're moving the files around, like perhaps you have a central db of all of your headers, well you can just use the regular "../../path/headerfiles/headerfile.h" path variables