Ah, yes, I forgot this aspect of C++.
I'm used to C#, where new is the only way to create a class instance
I should also add that in c++
new will return a pointer, so the correct code would actually be:
thingHandler* TH = new thingHandler(20);
Additionally, If you want a more compact statement, you can use the auto keyword.
auto TH = new thingHandler(20);
The example code has a few more issues that need to be addressed. Firstly, access modifiers are not set by prepending them to each member, instead you section them off like so:
class thingHandler
{
bool thingsAreHandled = false; // class members are private by default
public:
thingHandler(int start);
void handleThings(); // member function
int things;
};
Secondly, there was no declaration for the constructor, which I've added to the code above. Finally, knowing
new returns a pointer and memory allocated with it must be explicitly released, the main function should be adjusted as follows:
int main()
{
auto TH = new thingHandler(20);
TH->handleThings(); // use -> to access members of a pointer
TH->things += 10;
delete TH;
}