+ 2

How to initialize structure data type using constructor? ( If you don't understand my question see description.)

#include<iostream> using namespace std; class A { private: struct str { int dd,mm,yy; }; public: A() { } }; int main () { A a; } //Is it possible or not?

19th Dec 2020, 3:57 PM
Yawar Abbas
Yawar Abbas - avatar
3 odpowiedzi
+ 2
Shadow But there is no constructor here? Is it possible to initialize using structure or not?
20th Dec 2020, 11:20 AM
Yawar Abbas
Yawar Abbas - avatar
+ 1
Right now you only have the inner struct, but not an instance of it you could initialize. The class 'A' needs to store an object of the struct as a member field, since the struct itself is only the blueprint. If you include that, then initializing the object is possible, sure. Here is an example: https://code.sololearn.com/c9XR42pSK5zb/?ref=app
19th Dec 2020, 4:29 PM
Shadow
Shadow - avatar
+ 1
There are two constructors in the outer class in my code, so if that is not what you want, then I don't quite understand your question. It would be helpful to me if you could clarify the following: What do you want to initialize? Where and how do you want to initialize it? What do you want to initialize it with?
20th Dec 2020, 3:12 PM
Shadow
Shadow - avatar