IZ
Size: a a a
IZ
IZ
IZ
MK
MK
V
prog.cpp: In constructor ‘B::B()’:
prog.cpp:17:15: error: use of deleted function ‘A::A()’
B() : a("123"){
^
prog.cpp:8:2: note: declared here
A() = delete;
^
IZ
MK
prog.cpp: In constructor ‘B::B()’:
prog.cpp:17:15: error: use of deleted function ‘A::A()’
B() : a("123"){
^
prog.cpp:8:2: note: declared here
A() = delete;
^
B()
неявно вызывает A()
DK
B()
неявно вызывает A()
IZ
V
DK
#include <iostream>
using namespace std;
struct A{
std::string path;
A(const std::string& val){
this->path = val;
std::cout << "constructor string" << std::endl;
}
};
struct B : public A {
B() : A("123"){
}
};
int main() {
B b;
return 0;
}
C
#include <iostream>
using namespace std;
struct A{
std::string path;
A(const std::string& val){
this->path = val;
std::cout << "constructor string" << std::endl;
}
};
struct B : public A {
B() : A("123"){
}
};
int main() {
B b;
return 0;
}
MK
struct A{
std::string path;
A(){
std::cout << "constructor base" << std::endl;
}
A(const std::string& val){
this->path = val;
std::cout << "constructor string" << std::endl;
}
};
struct B : public A {
A a;
B() : a("123"){
std::cout << a.path << std::endl;
}
};
int main() {
B b;
return 0;
}
/*
stdout:
constructor base
constructor string
123
*/
path
инициализируется дефолтным конструктором, потом происходит переприсваиваниеLA
#include <iostream>
using namespace std;
struct A{
std::string path;
A(const std::string& val){
this->path = val;
std::cout << "constructor string" << std::endl;
}
};
struct B : public A {
B() : A("123"){
}
};
int main() {
B b;
return 0;
}
this->path
using namespace std;
, но при этом std::cout
и т.д.DK
this->path
using namespace std;
, но при этом std::cout
и т.д.LA
DK
DK
LA