Struct And CLASS

Hi . what is my fault . my compiler return this error for method setBBB()
expected primary-expression before '.' token|

#include<iostream>
using namespace std;
class AAA
{
public:
AAA();
void setBBB();
private:
struct BBB
{
int data;
};
};
int main()
{
AAA A;
A.setBBB();
return 0;
}
void AAA::setBBB()
{
cin >> BBB.data;
}
data is a member variable of the BBB struct. You need a BBB object to access it. Also, don't forget to implement your AAA constructor. This will work:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<iostream>
using namespace std;

class AAA
{
public:

    AAA(){}

    void setBBB();

private:

    struct BBB
    {
        int data;
    };

    BBB bbb;
};

int main()
{
    AAA A;
    A.setBBB();

    return 0;
}

void AAA::setBBB()
{
    cin >> bbb.data;
}
Thanksssssssssss m4ster r0shi
Topic archived. No new replies allowed.