banner
cells

cells

为美好的世界献上 code

Q016

Q016#

#include <iostream>

class A {
public:
    A() {
        std::cout << 'a';
    }
    ~A() {
        std::cout << 'A';
    }
};

class B {
public:
    B() {
        std::cout << 'b';
    }
    ~B() {
        std::cout << 'B';
    }
    A a;
};

int main() {
    B b;
}

Explain#

Member variables are initialized before constructor is called. The destructor is called before member variables are destroyed.

Answer#

click to see answer abBA
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.