General Project Start

Okay bear with me, convert from java and I normally command line code things. I want to start a decent sized project in c++, a game to be exact, and I don't quite understand the file structure behind a c++ program.

I tried codeblocks, but I always have trouble adding new code files, and to be honest I'd prefer command line, and my google skills are failing me in finding standard file structure.

In java, and hopefully I was doing it right, you just had a main file which could start everything up, and so long as things were in the same location as the main or were referenced correctly in packages, it would have access to all it needs and could run.

Is it similar in c++, and if I have to provide specific library access to users, such as qt, is there a standard for that?

Sorry if this isn't clear, don't know how else to phrase the question.
C++ is more flexible than Java.

A class is usually (but not necessarily) in a header file (extension .h or .hpp)
1
2
3
4
5
6
7
8
9
#ifndef A_H
#define A_H

class a
{
  void func();
};

#endif 
Notice the include guard:

https://en.wikipedia.org/wiki/Include_guard

The implementation may be (but again not necessarily) in the implementation file (extension usually .cpp):
1
2
3
4
5
6
#include <a.h> // Note: #include is similar to java import, but the concrete file name and eventually path is used

void a::func()
{
...
}


For #include see:

http://en.cppreference.com/w/cpp/preprocessor/include

It is also possible (like java) that the implementation appears in the header/interface.


The entrypoint is usually the function int main() { ... return 0; }, int main(int argc, char *argv[]) { ... return 0; }, or similar:

https://en.wikipedia.org/wiki/Entry_point

This entry point will usually be generated by the ide and might be even different (under windows).


To add a library to your project you need to add the inlcude path and the file name (probably with path) to your settings.
Thanks so much, this seems like it'll help me start the process!
Topic archived. No new replies allowed.