+ 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?
3 Respostas
+ 2
Shadow But there is no constructor here? Is it possible to initialize using structure or not?
+ 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
+ 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?