For some reason when I set some default values for the nested structure with a constructor, I get the following error. But it seems the code should work. Can someone tell me where am I going wrong?
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
struct smallDude
{
int int1;
int int2;
// Default constructor
smallDude()
{
int1 = 70;
int2 = 60;
}
};
struct bigDude
{
// structure within structure
struct smallDude second;
}first;
int main()
{
bigDude first = {{2, 3}};
cout<< first.second.int1<<endl;
cout<< first.second.int2;
return 0;
}
Error Output:
main.cpp:28:28: error: could not convert ‘{2, 3}’ from ‘’ to ‘smallDude’
28 | bigDude first = {{2, 3}};
| ^
| |
|