Automatically split (refactor) .h into header and implementation (h+cpp)

前端 未结 4 1387
花落未央
花落未央 2021-01-02 00:06

When writing C++ code, I often start by writing full \'implementation\' code in my header files, then later need to refactor the implementation into a .cpp file.

Th

相关标签:
4条回答
  • 2021-01-02 00:24

    You may be also interested in Eclipse's function "Refactor/Toggle function". It not always work properly however.

    0 讨论(0)
  • 2021-01-02 00:30

    There is Lazy C++ where you only write one .lzz file and it generates .h and .cpp for you.

    I am really looking forward for C++ modules where you only write .cpp and the import file is generated automatically. But we will have to wait for a few years even though Clang has started to implement modules. Here are some examples.

    0 讨论(0)
  • 2021-01-02 00:42

    You can use some tools such as Makeheaders

    http://www.hwaci.com/sw/mkhdr/

    but in general, these tools are not complete, especially meeting new c++11 files.

    0 讨论(0)
  • 2021-01-02 00:49

    C++20 modules essentially do that for us

    As mentioned at: https://quuxplusone.github.io/blog/2019/11/07/modular-hello-world/ clang 2019-11 implements it along:

    clang++ -std=c++2a -c helloworld.cpp -Xclang -emit-module-interface -o helloworld.pcm
    clang++ -std=c++2a -c -fprebuilt-module-path=. -o helloworld.o helloworld.cpp
    clang++ -std=c++2a -fprebuilt-module-path=. -o main.out main.cpp helloworld.o
    

    where:

    • helloworld.cpp contains the implementation
    • helloworld.pcm is a precompiled module, basically an auto-extracted header from the .cpp (but in a clang internal language format) which gets used by main.cpp without an .hpp

    So basically clang is the tool, and thus parsing is perfect.

    0 讨论(0)
提交回复
热议问题