How do I create a construct in C++ structure? I want to define the constructor, but I don't know the grammar
c++ struct constructor
C and C++ structures look similar, but they are actually different data structures.
In C++, class
and structure
are
Only the is different, and the other functions are the same.
Therefore, when defining the constructor of a structure in C++, you can write the name of structure
just like class
.
:
.struct foo{
int a, b;
foo() : a(0), b(0) {
cout << "foo made" << endl;
}
};
int main(){
struct foo f1;
}
© 2024 OneMinuteCode. All rights reserved.