Private
members of structs and classes are called "private" because they can only be accessed from within the class/struct.
If you want to keep the struct private try to initialize its values during the construction of the class.
Like this:
#include <vector>
#include <string>
class A{
public:
//constructor for two students
A(const std::string &student1, const int rollNo1, const std::string &student2, const int rollNo2){
m_student.push_back(Student(student1, rollNo1));
m_student.push_back(Student(student2, rollNo2));
}
private:
struct Student
{
std::string name;
uint32_t rollno;
//explicit constructor for the struct
Student(const std::string &Name, const int rollNo){
name = Name;
rollno = rollNo;
}
};
std::vector<Student>m_student; //we need some container to store the students in the class
};
//usage
int main()
{
A myClassInstance("Luffy", 1, "Nami", 2);
return 0;
}
Obviously there are much better ways to do this, add an "addStudent" public member function to the class that can add a member.
Also make sure you are using an unnamed namespace for the correct reasons :-) Check this thread out: Why are unnamed namespaces used and what are their benefits?