#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct Third
{
int first;
double second;
bool third;
};
struct Second
{
Third fifth;
char other;
};
Second fourth = {{1,2.2,true},'F'};
void p(Second zero)
{
int &a = zero.fifth.first;
double &b =zero.fifth.second;
bool &c = zero.fifth.third;
std::cout<<"Third: "<<a<<"\n";
std::cout<<"Second: "<<b<<"\n";
std::cout<<"First: "<<c<<"\n";
std::cout<<"Four: "<<zero.other;
}
int main()
{
p(fourth);
return 0;
}
//Код сверху пропускает без проблем с ожидаемым результатом,
//но код снизу вызывает краш в месте инициализации переменной (Second fourth). Коды практически идентичны, объясните, что не так? Error: unknown type name 'fourth'
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
struct Third
{
int first;
double second;
bool third;
};
struct Second
{
Third fifth;
char other;
};
Second fourth;
fourth.fifth.first = 1;
fourth.fifth.second = 2.2;
fourth.fifth.third = true;
fourth.other ='f';
void p(Second zero)
{
int &a = zero.fifth.first;
double &b =zero.fifth.second;
bool &c = zero.fifth.third;
std::cout<<"Third: "<<a<<"\n";
std::cout<<"Second: "<<b<<"\n";
std::cout<<"First: "<<c<<"\n";
std::cout<<"Four: "<<zero.other;
}
int main()
{
p(fourth);
return 0;
}