I was wondering how one would go about creating a structure that cannot be used by itself, i.e. only through a wrapper class.

My question is what would be the syntax for this construct?

I'm currently on a personal project to make simple tests from old tests, all the questions will be written into a binary repository and seekable through this application. If anyone's interested it's for the Irish Leaving Certificate.

The way I've done it so far is as follows:

From classes.hpp

class Student {

    public:
        static int numberofstudents = 0;

        Student(string name);
        ~Student();
    private:
        struct address; //Forward declaration of the structure as private.

        string name;
        int id;
};

struct Student::address{

    int housenumber;
    string roadname;
    bool isdublin;
    int dublinareacode;
    string countyname;
}

I'm not sure if this is correct however.

You can place the entire (nameless)struct's declaration in the class header.

e.g.:

class myWrapper
{
    struct 
    {
        int houseNumber;
    } address;

    public:
        myWrapper() { address.houseNumber = 555; } // this is valid
};

int main
{
    No way to access address from here, apart from a public interface.
}
This question has already been answered. Start a new discussion instead.