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

1. Where can I find the Employee.cpp file in the code?

The Employee.cpp file can typically be found in the source code folder of the project, or in a specific folder designated for storing class files.

2. Is the Employee.cpp file always located in the same place in every codebase?

No, the location of the Employee.cpp file may vary depending on the project structure and organization preferences of the development team.

3. Is it possible for the Employee.cpp file to be located outside of the project's source code folder?

Yes, in some cases, the Employee.cpp file may be located in a separate directory or repository, especially in larger projects with multiple codebases.

4. Can the Employee.cpp file be renamed or moved to a different location?

Yes, the Employee.cpp file can be renamed or moved to a different location as long as the changes are reflected in the project's build configurations and any other relevant files.

5. Is it essential to know the exact location of the Employee.cpp file in order to run the code?

Yes, the Employee.cpp file is an essential component of the code and must be located in the correct place for the code to compile and run successfully.

Similar threads

  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
2
Replies
65
Views
5K
  • Programming and Computer Science
3
Replies
89
Views
4K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
5
Views
818
  • Programming and Computer Science
Replies
33
Views
2K
  • Programming and Computer Science
Replies
6
Views
2K
Replies
10
Views
960
Back
Top