Ali Alavi
Ali Alavi

Reputation: 2467

How to automatically generate function headers for .h file in Clion?

When writing a library in C, I usually end up implementing functions before defining them in the corresponding header file. As copying function header's in the header file is a repetitive task, I was wondering if I can automatically generate function headers (or even better, the full header file) in CLion?

Upvotes: 32

Views: 16653

Answers (2)

jtbr
jtbr

Reputation: 1179

This only works for C++, but after you've written a function definition in a cpp file, eg:

void MyClass::myNewFn() { ... }

you can do Alt-Enter on myNewFn and select 'Create new function myNewFn()'. This will add a declaration of MyClass in the header file.

Upvotes: 2

prophet-five
prophet-five

Reputation: 559

Maybe it's a little late (about 4 years), but here's the best way i've found (for a c file):

cut and paste the contents of the .c in the .h file, and for each function, put the cursor on it's name and press Alt+Enter, and choose "Split function into declaration and definition".

this will keep the declaration in the .h file while moving the implementation to the .c file.

hope it helps someone.

Upvotes: 21

Related Questions