Nested Structures

Error says that "field warmss has incomplete type"
How do I declare another structure inside a nested structure ?
How do I use them in my inputs and outputs?
I could only manage to do a nested structure.
Order is my nested structure and I want another structure inside it which is item.

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
34
35
36
37
38
39
40
41
#include<iostream>
#include<sstream>
#include<string>
#include<iomanip>
using namespace std;

int main ()

{   struct Order{
           int day;
           int month;
           int year;
           int quantity;
           struct item warmss;
           };
           struct item{
                  int id;
                  string iname;
                  int price;
                  };
    struct Name{
           string last;
           string first;
           };
    
    struct Customer{
           struct Name cool;
           string contact;
           struct Order hot;
           };
           
    Customer C;
    Order O;
    cin >> C.hot.day;
    cout << C.hot.month;
    system("pause");
    return 0;
    }
        

closed account (LNboLyTq)
Hi hpacleb,
Why did you put all struct definitions in a function?
'item' is defined below struct 'Order'; the compiler does not know the type of 'warmss' since the struct 'item' is not yet defined.

You might want to change your code a bit.
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
34
35
36
37
38
39
40
41
#include<iostream>
#include<sstream>
#include<string>
#include<iomanip>
using namespace std;

           struct item{
                  int id;
                  string iname;
                  int price;
                  };

 struct Order{
           int day;
           int month;
           int year;
           int quantity;
           item warmss;
           };

    struct Name{
           string last;
           string first;
           };
    
    struct Customer{
           struct Name cool;
           string contact;
           struct Order hot;
           };

int main ()
{  
    Customer C;
    Order O;
    cin >> C.hot.day;
    cout << C.hot.month;
    system("pause");
    return 0;
    }
        


Hope this helps,
Andy.
Topic archived. No new replies allowed.