Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

This is great, but I find this process laborious, but otherwise pretty easy, so I wondered about whether is there any automated way to do this?

Specifically, I want to convert all class and function definitions in the .h to declarations, and have them declared in a new .cpp file.

I'm using xcode, but I am open to any solutions.

like image 649
aaaidan Avatar asked Jun 25 '12 06:06

aaaidan


3 Answers

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.

like image 58
Juraj Blaho Avatar answered Oct 04 '22 04:10

Juraj Blaho


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.

like image 31
lenx.wei Avatar answered Oct 04 '22 02:10

lenx.wei


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

like image 22
peper0 Avatar answered Oct 04 '22 04:10

peper0