In the .cpp, is there a way to auto-implement all the functions from its .h? - c++

I think this would increase the quality of life when devving, but google came up with nothing and I couldn't find anything specific inside inside Netbeans either.
What I want is to start with this header:
class bla
{
public:
static void gfg(somearg asd);
};
Then I open the blank bla.cpp and pressed 'autoimplement'. After that, it would look like this:
#include "bla.h"
static void bla::gfg(somearg asd)
{
//TODO: implement
throw unimplemented("void bla::gfg(somearg) is unimplemented");
}
Anyone know of a tool like this?

I found http://www.radwin.org/michael/projects/stubgen/
"stubgen is a C++ development tool that keeps code files in sync with their associated headers. When it finds a member function declaration in a header file that doesn't have a corresponding implementation, it creates an empty skeleton with descriptive comment headers."
This looks like it does exactly what you want it to do.

Some time has passed and in the meantime the requested feature seems to have been implemented in netbeans. Refer to https://netbeans.org/bugzilla/show_bug.cgi?id=213811 , which also gives a description on how to use it:
Note:
Implemented CTRL+SPACE.
IDE suggest implementing of class method if CTRL+SPACE was pressed:
- inside file that already has at least one method definition
- between method declarations

Related

load config file for game, singleton or passing down the tree or anything else?

I'm trying to create simple game in C++. At one point I want to have some setting, save and load from config file.
The config file should be read from the beginning, and should be accessible anywhere it needed.
So far I only see Singleton pattern as a solution.
Another way is to create an object an pass it down, but it can mess
up the current code.
I've also search and found something called Dependency Injection.
Is dependency injection useful in C++
Which design patterns can be applied to the configuration settings problem?
But I don't quite understand it, you still have to create an object in main and pass it down, right?
Singleton is quite simple, but some consider it antipattern, while pass it down the tree can mess up my current code. Is there any other Patterns?
P/S: I'm also curious how games load their setting.
I would suggest something simple as the following example, which circumvents any singleton-related or initialization order issue:
struct global_state
{
config _config;
};
struct game_state
{
global_state& _global_state;
};
int main()
{
global_state globals{load_config_from_file()};
game_state game{globals};
game.run();
}
Since _global_state is a member of game_state, it can be used in member functions without the need of explicitly passing it as a parameter:
void game_state::update_ui()
{
const float text_size = _global_state._config.get_float("text_size");
_some_text.set_size(text_size);
}

Project structure in C++ in relation to publicly exposed headers

I am trying to understand project structure in c++, I am finding it difficult to get my head around class structure and header files.
Extract from article 1 (linked at bottom of this post)
By convention, include directory is for header files, but modern practice > suggests that include directory must strictly contain headers that need
to be exposed publicly.
My first question of this process is with regards to a separate class file that is within the include directory.
What is purpose of exposing your headers?
Following on from this, looking at an example of an exposed header file. Linked in the following GH repo: https://github.com/AakashMallik/sample_cmake
How does the Game_Interface class relate back to the Game_Engine?
game_interface.h
#pragma once
#include <game_engine.h>
class GameInterface
{
private:
GameEngine *game;
public:
GameInterface(int length);
void play(int num);
};
I have looked else where for a simple explanation of this process but, all I have found so far is nothing that can be understood in the context of this example.
Fairly new to C++ background in web technologies.
Link to article 1: https://medium.com/heuristics/c-application-development-part-1-project-structure-454b00f9eddc
What is purpose of exposing your headers?
Sometimes you may be developing some functionality or a library. You might want to help some other person or customer or client by sharing the functionality of your code. But you don't want to share the exact working details.
So for instance you wish to share an Image processing functionality which applies beautiful filters to it. But at the same time you don't want them to exactly know how did you implement it. for such scenarios, you can create a header file, say img_filter.h having function declaration -
bool ApplyFilter(const string & image_path);
Now you can implement entire details in img_filter.cpp:
bool ApplyFilter(const string & image_path)
{
....
// Implementation detail
...
}
Next you can prepare a dll of this file which could be used by your client. For reference of working, parameters, usage etc. you can share the img_filter.h.
Relation with Interface:
A well defined interface is generally nice to have so you can change implementation details transparently, which means, that HOW you implement the details don't matter as long as the interface or the function name and parameters are kept intact.

How to configure Eclipse/CDT/C++ formatter to not break line between a function returned type and the function name [duplicate]

I ran into a problem with the Eclipse formatter. It won't format my code correctly when declaring methods within a class declaration. It puts a new line after the method's return type.
I already exported the style xml file and examined the settings in it, but none of the settings have any apparent connection to this problem, and the settings editor in Eclipse didn't show the same problem happening in it's sample code for method declarations.
Here is an example bit of code for what I want to have happen:
class MyClass
{
public:
MyClass();
void myMethod();
};
However, this is what I get:
class MyClass
{
public:
MyClass();
void
myMethod();
};
Again, in the styles editor, the code doesn't have this problem and looks just how I want it to, but in the actual code, the story is different.
I'm using version 3.8.0. Any help is appreciated.
Edit: I deleted those source files that were formatted incorrectly (after formatting the code several times to no avail) and replaced them with "identical" files with the same methods, same structure, etc. I formatted the code this time and it worked. This is probably a bug, but I'm leaving it up just in case anyone else encounters a similar problem or has a solution to avoiding this problem in the first place.
I hand edited two files under the main eclipse projects directory
.metadata\.plugins\org.eclipse.core.runtime\.settings
The two files:
file 1: org.eclipse.cdt.core.prefs, change this line from "insert" to "do not insert"
org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert
file 2: org.eclipse.cdt.ui.prefs,
scan this file for "insert_new_line_before_identifier_in_function_declaration" and make a similar change from insert to do not insert next to it, should be obvious
Note I seen this problem on indigo and juno, the fix described above was in juno.
If you have a custom formatter config, export it first (settings>C/C++ General>Formatter>Edit>Export). Then change the following line to "do not insert". Save the XML.
<setting id="org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration" value="do not insert"/>
Delete the current config and import the one you changed.
There's a specific preference in the formatter options starting from cdt 9.8 included in Eclipse 2019-06.

Anyway to get Visual Studio C++ to autocomplete parameter list?

Very specific issue with a specific piece of software, but I hope you fine folks can help!
I define a class in a header.h file that has a few method declarations that take parameters
class Lazy{
void complainForever(char * complaint, float forever = INFINITY);
};
Then I go into the Lazy.cpp file to define that function. Here is a psuedo timelapse of just how lazy I am.
void Lazy:: // <-- autocomplete kicks in, select method and hit enter
void Lazy::complainForever // <-- parameter list missing, completely defeating purpose
At that point, I either have to type it by hand, or copy/paste the parameter list from the header.h file
The question is this! Is there a keyboard shortcut or any method at all for having autocomplete take care of the parameter list for me?
Thank you in advance!
Why don't you try Visual Assist X. It isn't free though.
Once you are done defining the class in your header file, try to update Intellisense.
Updating intellisense can be achieved by reloading your project/solution. Once your intellisense is update, when you try to implement the class definition - you get the autocomplete feature on your newly defined class enabled. This includes the individual function prototypes as defined in the header.
Keyboard shortcut to display intellisense is Ctrl + Space.
Thanks

How do you call a function using self in cocos2d 0.99.5

Yes I am a begginer. I am reading a book on cocos2d development. The author wrote this book using 0.99.4. In the book, it says to call a function that creates sprites and adds them to an array by using the following code: [self initSpiders];. But when I run this, I get a warning that says "'Gamescene may not respond to'-resetSpiders'". I am assuming that there is an updated way of doing this in the newer version of cocos2d. If there is, I would be thankful if someone could explain the proper way of going about this. If this is the correct way, then what am I doing wrong? Thanks in advance.
In objective-c, an object tells a message to do something:
[someObject doSomething];
Or with an argument:
[someObject doSomethingWithArgument:someValue];
The message you get from the compiler is telling you that the object (eg. "someObject") does not understand what you are telling it to do (doSomething).
To make that compiler warning go away, check the following:
Did you #include the header file of the class your "someObject" is an instance of?
Does that header file in fact have the method you are calling? (including arguments?)
If you are calling a method you wrote, make sure you put that method in the header file. If you are calling a method that someone else wrote, or is part of the OS; make sure you include the header file, then perhaps find the method in the header file and copy/paste it into your code. This will make sure you get the EXACT method signature. These two are not the same:
[self generateSprites]; // note the capitol S
[self generatesprites]; // method names are case sensitive
If you need a better answer, you'll need to post some of your code so that people can see what you're doing wrong.