Andrei
Andrei

Reputation: 13

In Visual Studio Code, why does the it auto-create the "main::main and main::~main", besides the class?

So when using the "intellisense", when I want to create a class, it also creates those other two functions (not sure if I am calling them right):

class main
{
private:
    /* data */
public:
    main(/* args */);
    ~main();
};

main::main(/* args */)
{
}

main::~main()
{
}

Why is that? How are they useful and also is the "~" the bitwise NOT ?

Upvotes: 1

Views: 668

Answers (1)

Swift - Friday Pie
Swift - Friday Pie

Reputation: 14614

Those are special member functions, a user-defined default constructor and user-defined destructor.

VS Code specifically does it because Microsoft corporate code style requires always to have constructor\destructor in class. To the point where in older versions of their compilers default initialization for trivial classes never was a value (zero) initialization (non-compliant with standard). C++ does not have such requirement in rules, this makes class not a trivial\POD.

As usual, their IDE does only half of job. With such spproach, one needs to define five functions, not two, see "rule of zero".

Upvotes: 1

Related Questions