Skip to content

How could open the client-side socket ? #899

Answered by tt4g
dgasacas7 asked this question in Q&A
Discussion options

You must be logged in to vote

In C++, all member variables are initialized before the constructor body is evaluated.
If not explicitly initialized, the compiler calls the default constructor.

Example (run online):

#include <iostream>
#include <cstdlib>

class Foo
{
public:
    Foo()
    {
        std::cout << "FOO initialized!" << std::endl;
    }

    explicit Foo(int)
    {
        std::cout << "FOO(int) initialized!" << std::endl;
    }
};

class Bar
{
public:
    Bar()
    { // Output: FOO initialized!
        foo = Foo(1); // Output: FOO(int) initialized!
    }
private:
    Foo foo;
};

int main()
{
    Bar bar;
}

To avoid this, initialize member variables before the constructor body: https://en.cppreference.com/…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@dgasacas7
Comment options

@tt4g
Comment options

@dgasacas7
Comment options

@tt4g
Comment options

Answer selected by dgasacas7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants