asked 82.8k views
4 votes
Which kind of error will occur for the following scenario? you have 3 files- 1. employee.h which has the class definition for employee, 2. employee.cpp which has the class implementation for employee, and 3. main.cpp. 64.8% then you forget to implement a method defined in employee.h in employee.cpp. 1. syntax error 2. linker error 3. compiletime error 4. runtime error?

1 Answer

2 votes

Final answer:

When a method declared in a header file is not implemented in the corresponding source file, a linker error occurs during the program build process.

Step-by-step explanation:

If you forget to implement a method that's declared in employee.h inside employee.cpp, the type of error that will occur during the building of your program is a linker error. This error arises when the linker attempts to construct the final executable and cannot find the definition for the member function that was declared in your class definition.

While syntax errors are detected during the source code analysis (parsing) phase and deal with incorrect use of the language grammar, a linker error is concerned with resolving references in the compiled object files or libraries. Linker errors do not manifest at runtime, but rather at the link stage after the compilation when all object files are combined to form a single executable or library.

In your scenario, because the method implementation is missing in the corresponding source file (employee.cpp), the linker cannot find the necessary code to link to when building the final output, resulting in an error.

The error that will occur in this scenario is a linker error. A linker error happens when the compiler is unable to find a definition for a function or a variable that is being referenced in the code. In this case, you forget to implement a method that was defined in the employee.h file in the employee.cpp file, causing the linker error.

answered
User MorganGalpin
by
8.1k points