I am building a very small application to help me learn C++ and its quirks, and I have run into a wall with my development. I keep getting this error and don't know how to solve it. In the code below, I am trying to create an instance of the user class in the main function (not shown). I don't understand exactly where I am going wrong; any help anyone can provide is appreciated.
Undefined symbols for architecture x86_64
"User::User()", referenced from:
_main in main-e8c60e.o
_main in main-dac910.o
Here is my header file
#include <string>
#include <iostream>
class User
{
private:
std::string firstName_;
std::string lastName_;
std::string favGenre_;
int userAge_;
public:
/**
* @brief Construct a new User object
*
* The user class creates a new user object with all users' information.
* On initialization, it will create the instance of the BookLocker class
* and be on standby as the User uses the OpenLibary class.
*
*/
User();
// Set name for current user
void setName();
// Set favorite genre for user
void setGenre();
// Set the users age
void setAge();
// Get users name
std::string getName();
// Get the users favorite genre
std::string getGenre();
// Get the users age
int getAge();
};
Here is the implementation
/**
* A class that represents the User gathering their information and creating
* an instance of the book locker alongside its creation.
*
*/
#include <iostream>
#include <string>
#include "../include/User.h"
/// Initialize the user object
User::User()
{
std::cout << "What is your first name?" << std::endl;
std::cin >> firstName_;
std::cout << "What is your last name? " << std::endl;
std::cin >> lastName_;
std::cout << "What is your favorite literature genre? " << std::endl;
std::cin >> favGenre_;
std::cout << "How old are you? " << std::endl;
std::cin >> userAge_;
}
void User::setName()
{
std::cout << "What is your first name?" << std::endl;
std::cin >> firstName_;
std::cout << std::endl;
std::cout << "What is your last name?" << std::endl;
std::cin >> lastName_;
}
void User::setAge()
{
std::cout << "What is your age?" << std::endl;
std::cin >> userAge_;
}
void User::setGenre()
{
std::cout << "What is your favorite genre?" << std::endl;
std::cin >> favGenre_;
}
int User::getAge()
{
return userAge_;
}
std::string User::getName()
{
return firstName_ + " " + lastName_;
}
std::string User::getGenre()
{
return favGenre_;
}
Any help on this would be greatly appreciated. Thank you.