I am learning structures in C++. Got the following error while executing the code:
Error: Too many initializer for CompData.
It would be great if someone could point out the mistake.
Code:
#include <iostream>
#include <string>
struct EmpData
{
std::string name;
int age;
double salary;
};
struct DepartmentData
{
std::string departmentName;
struct EmpData;
};
struct CompData
{
std::string compName;
struct DepartmentData;
};
int main()
{
CompData DeltaF
{
"DeltaF",
{
"Product Development",
{
"Steve", 35, 1223
}
}
};
}
struct EmpData;doesn't do what you think it does. You need something likeEmpData data;structkeyword to declare a variable with a structure type, like you need with C. What you are actually doing in yourDepartmentDatatype is declaring a nested type.