Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to organize c++ header and cpp files?

I'm not sure if i'm asking a valid question, but here goes.

I have c++ solution with a structure of

[folder] Header files -

... 200 header files ..

[folder] Source files -

... 200 soure files ..

... rest

Is it possible to organize header and soure files by folders as you would in a C# project? The problem I'm facing is, as the project grows, it gets tiresome to navigate through a huge pile of files, which would be much easier to navigate to, if they were organized by functionality (such as folders and namespaces in c# projects).

Is there a some kind of standard, that would be supported by a wide variety of compilers and not Visual Studio alone ?

Example:

[folder] Header files -

  • [folder] X domain
    • 100 header files
  • [folder] Y domain
    • 100 header files

[folder] Source files -

  • [folder] X domain
    • 100 cpp files
  • [folder] Y domain
    • 100 cpp files

... rest

like image 372
Dante Avatar asked Sep 10 '12 22:09

Dante


People also ask

Can C++ use C header files?

If you are including a C header file that isn't provided by the system, you may need to wrap the #include line in an extern "C" { /*... */ } construct. This tells the C++ compiler that the functions declared in the header file are C functions.

Should header file include cpp?

The headers will never get compiled, unless included in a cpp file first. Typically headers are declarations and cpp are implementation files. In the headers you define an interface for a class or function but you leave out how you actually implement the details.

What do you put in .h and .cpp files?

The short answer is that a . h file contains shared declarations, a . cpp file contains definitions and local declarations. It's important that you understand the difference between declarations and definitions.

Can I create custom header file in cpp?

Yes, you can create your own header file. Kindly go through thinking in c++ by bruce eckel vol 1. These files have declaration of user defined data structures and interfaces such has class declaration, function prototypes and etc.


1 Answers

Header/Source file is not a requirement imposed by Visual Studio. That's just the default layout, and it's virtual, not physical. If you click "Show all files" in the solution explorer, it will show the folder tree as it is on the hard drive- which you can manipulate as you see fit. This is the only sane configuration and I have no idea why the default is that way. Plus, naturally, they fixed it for C# projects but not C++.

like image 154
Puppy Avatar answered Sep 19 '22 19:09

Puppy