Where is the Employee.cpp file located in the code?

  • C/C++
  • Thread starter member 428835
  • Start date
  • Tags
    Error Mac
In summary, the CLion IDE and a mac are involved, two files are stored on the user's desktop, and when the "run" button is clicked, the user gets an error message.
  • #1
member 428835
I have the following two files stored in the folder "impl" on my Desktop, the CLion IDE and am running on a mac: main.cpp:
C++:
#include <iostream>
#include "Employee.h"

int main() {

Employee e1("Bradly", "E007");
    Employee e2("John", "E425");

    std::cout << e1.getName() << ": " << e1.getId() << "\n";
    e1.setName("Brad");
    std::cout << e1.getName() << ": " << e1.getId() << "\n";
    std::cout << e2.getName() << ": " << e2.getId() << "\n";

    return 0;
}

and then a header file Employee.h

C++:
#pragma once
#include <string>

class Employee
{
public:
Employee(std::string name, std::string id);

    std::string getName() const;
    std::string getId() const;

    void setName(std::string name);

private:
std::string m_name;
    std::string m_id;
};

When clicking the green triangle "run" (see the arrow in the image) I get the error the image shows (see the file structure upper left if this helps):
Screenshot 2023-02-07 at 11.24.16 PM.png

Any idea what I'm doing wrong? Thanks so much!
 
Technology news on Phys.org
  • #2
Aren't you supposed to provide implementations for the getter and setter functions in your employee class definition?

Something along the lines in this example:

https://cplusplus.com/forum/beginner/254961/

where you can see implementation code for the getters and setters. The getters return the private attribute like m_name or m_id and the setter updates the m_name attribute.

Your errors as best as I can read the tiny print in your screencap indicate that the getter and setter methods are undefined symbols.
 
  • #3
jedishrfu said:
Your errors as best as I can read the tiny print in your screencap indicate that the getter and setter methods are undefined symbols.
Your eyes are better than mine. Screen shots of error messages often turn out to be completely unreadable, in my experience. Even worse is with white letters against a black background.

In future posts, @joshmccraney, please copy the text of the error messages and post it here, rather than a screenshot.

jedishrfu said:
Aren't you supposed to provide implementations for the getter and setter functions in your employee class definition?
This code is a very simple example. It should be obvious that the header file contains only declarations of these two class methods, with no definitions for them. Of course, the linker will complain.
 
  • Like
Likes Vanadium 50
  • #4
Mark44 said:
Screen shots of error messages often turn out to be completely unreadable,
I do so enjoy the gray-on-gray color scheme.

If the OP had to type in the error message, it might have caused him to think about what it meant and pointed him in the right direction. We have at least two members here who post "PF! Debug my code for me!" messaged and I see no signs of progress from either.

OP, if you thought this code could ever possibly have worked, you are missing a very important thing about classes and methods. (Maybe even programming in general) I would jump back several chapters and try and fill the gaps before moving on.
 
  • #5
He could simply copy and paste the error messages no need for a screenshot or retyping the message.
 
  • #6
jedishrfu said:
He could simply copy and paste the error messages
This is true. But I hope writing them himself might trigger some thinking.
 
  • Like
  • Haha
Likes Mark44 and jedishrfu
  • #7
From post #3:
Mark44 said:
In future posts, @joshmccraney, please copy the text of the error messages and post it here, rather than a screenshot.

Post #5:
jedishrfu said:
He could simply copy and paste the error messages no need for a screenshot or retyping the message.
 
  • Like
Likes jedishrfu
  • #8
Wow, I definitely forgot about writing a .cpp file. Feel like a moron looking back at this now, but thanks for the help! And in the future I'll post the error in text rather than a screenshot. Thanks so much to you all!
 
  • Like
Likes berkeman, jedishrfu, jtbell and 1 other person
  • #9
Yeah, that was my first thought when I saw the code in the opening post: "Where's Employee.cpp?" :confused:
 
  • Like
Likes jedishrfu

FAQ: Where is the Employee.cpp file located in the code?

Where is the Employee.cpp file located in the code?

The Employee.cpp file is typically located in the source code directory of the project. This file contains the implementation of the functions and methods defined in the corresponding Employee.h header file.

How do I find the Employee.cpp file in a large codebase?

In a large codebase, you can use the search functionality of your integrated development environment (IDE) or text editor to look for the Employee.cpp file. You can search for the file name or use specific keywords related to the Employee class to narrow down the search results.

Can the Employee.cpp file be located in a different directory than the source code directory?

Yes, the Employee.cpp file can be located in a different directory than the source code directory. This is common in projects that follow a specific directory structure or organization. In such cases, the build system or configuration should be updated to include the correct path to the Employee.cpp file.

What should I do if I cannot find the Employee.cpp file in the codebase?

If you cannot find the Employee.cpp file in the codebase, you should check if it has been accidentally deleted or moved to a different location. You can also consult with your team members or project documentation to see if there are any specific conventions or practices regarding the location of source files.

Is it possible for the Employee.cpp file to be generated dynamically during the build process?

Yes, it is possible for the Employee.cpp file to be generated dynamically during the build process. This can happen in projects that use code generation tools or templates to create source files based on certain specifications or configurations. In such cases, the Employee.cpp file may not exist in the codebase but will be generated during the build process.

Similar threads

Replies
22
Views
3K
Replies
6
Views
10K
Replies
75
Views
5K
Replies
118
Views
8K
Replies
89
Views
5K
Replies
65
Views
5K
Replies
89
Views
5K
Replies
5
Views
4K
Back
Top