-1

i am beginner in c++ programming, I a have struct Employee: Please see the code,

struct Employee
{
    int emp_ID = 0;
    string emp_Name = "";
    string emp_Address = "";
    string emp_Contact_Number = "";
    string em_position = "";
    string dt_emp_started = "";
};

and trying to call it inside int main like,

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <cstdio>
#include <windows.h>
using namespace std;

int main(){
   Employee emp;
   cout<< "Employee ID : " , cin >> emp.emp_ID;
}

but it returns this error,

'Employee' undeclared identifier.

Did i do it wrong? What should I do to fix it? thanks and regards

1 Answers1

3

In the line where you are declaring the Employee variable, you must have previously defined what an Employee is. So, you have to either define the struct above in the same file, or if defined in another file, eg employee.hpp you should #include that file.

If you are just declaring a reference or pointer to that type, or declaring a function which accept or return it, you can forward declare the type (although that seems not your case), as this post explains

nsm
  • 319
  • 1
  • 9