This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 270516

Summary: Create function declaration in .h when definition is created in .cpp file
Product: cnd Reporter: antoniocs <antoniocs>
Component: EditorAssignee: Alexander Simon <alexvsimon>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: Dev   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description antoniocs 2017-04-28 16:39:42 UTC

Would it be possible to have netbeans generate the function declaration when I create a class function in the cpp file?

So for example in class.cpp I create this:

void classname::func() {

Then netbeans can have something that generates the declaration in the .h file (normally it's the same name as the class file but with .h or hpp)

So this would be generated:

void func();

This would have to be set in either the public, private or protected blocks.

Would this be possible to add?
Comment 1 Vladimir Voskresensky 2017-04-28 17:41:12 UTC
Hello Antonio,

yes, it is possible to implement. Thanks for the enhancement report.
For now I can recommend to use reverse steps:
- declare method foo (in appropriate private/protected/public section) in header inside class
- switch to source file (Ctrl+Shift+A)
- invoke code completion on empty line in file scope (between other methods)
- use "generate foo"
It saves quite a few time for me ;-)
Comment 2 Vladimir Voskresensky 2017-04-28 17:44:42 UTC
there is also  "Extract method body from class declaration"
Comment 3 antoniocs 2017-04-28 18:09:33 UTC
Thanks Vladimir Voskresensky. 

I never thought about doing it that way but I can see the benefits. (thanks also for the shortcut to switch between .h and .cpp and vice-versa).

Not sure how to utilize the "Extract method body from class declaration" feature you linked to. I always feel that for C++, netbeans is good IDE but the documentation/examples are always behind Java or PHP.

Thanks again.
Comment 4 Vladimir Voskresensky 2017-04-28 21:17:46 UTC
> Not sure how to utilize the "Extract method body from class declaration"
> feature you linked to. 
I use it when inline-method in class body grows from one line to multiple, i.e. impl need to use declarations which were not in #include sections for header, but now are needed for impl.
So just go to source and extract body... then add #include only in source file reducing (re)compilation time.