How do I declare a struct within a class?
c++
Solution
You've describe a type called "p" which is a struct. There is yet no thing of type p around. Therefore your
p->...
calls make no sense.
Try declaring
p pInstance;
in your class and using it, ie:
void setme()
{
this->pInstance.grade=99;
this->pInstance.name[25]='g'; //here is the problem
}
Note even with this your assignment to name[25] will fail as the allowed indices for that array are 0 up to 24 (totalling 25 elements).
Problem
I want to declare a struct within a class which is private and I want to give a character value to a variable in the same struct, but I can't initialize it or cin it: ``` class puple { private: struct p { char name[25]; int grade; }; public: puple(){}; void setme() { this->p::grade=99; this->p::name[25]='g'; //here is the problem } void printme() { cout<<"Name: "<<this->p::name<<endl; cout<<"Grade: "<<this->p::grade<<endl; } }; void main() { puple pu1; pu1.setme(); pu1.printme(); } ```