accessing nested inner class struct from outer class

class A
{
 class B;
 B::data myData; //Error: incomplete type not allowed.

    class B
    {
    public:
        struct data
        {
        int number;
        };
    };
};

In the code above, how could I declare a member variable of type data in class A?

Answers


B must be defined before you use it in the declaration of A::myData:

class A
{
    class B
    {
    public:
        struct data
        {
            int number;
        };
    };

     B::data myData;
};

I think all you need to do is put the class definition in front of the declaration of the variable. The compiler has no idea what is inside class B, only that it exists, until it encounters the actual definition of the class


Need Your Help

How to instatiate a class from another class in Qt C++

c++ qt

I had made 2 class in my project. I want to use a function from 1st class to the 2nd class the problem is I can't instantiate the 1st class to the 2nd class. By the way both classes were declared in

apk fails to run on some devices

android apk corona

I have a quick question. I have built an app in Corona SDK (Version 2012.878). My app works fine on my Galaxy S. But it fails to install on HTC Wildfire S.