Gold Member
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 e2("John", "E425");

std::cout << e1.getName() << ": " << e1.getId() << "\n";
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):

Any idea what I'm doing wrong? Thanks so much!

Mentor
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.

Mentor
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.

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.

Staff Emeritus
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.

Mentor
He could simply copy and paste the error messages no need for a screenshot or retyping the message.

Staff Emeritus
He could simply copy and paste the error messages
This is true. But I hope writing them himself might trigger some thinking.

Mark44 and jedishrfu
Mentor
From post #3:
In future posts, @joshmccraney, please copy the text of the error messages and post it here, rather than a screenshot.

Post #5:
He could simply copy and paste the error messages no need for a screenshot or retyping the message.

jedishrfu
Gold Member
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!

berkeman, jedishrfu, jtbell and 1 other person
Mentor
Yeah, that was my first thought when I saw the code in the opening post: "Where's Employee.cpp?"

jedishrfu