I am new to C++ and I can't figure out the problem I am having with importing a class from another file. I am running and compiling on main.cpp below:
#include <iostream>
using namespace std;
#include "deck.h"
using namespace deck_base;
int main() {
card new_card;
cout << new_card.val;
}
I also have a deck.h header file and a deck.cpp implementation file, shown below in that order:
//deck.h
#include <iostream>
namespace deck_base {
class card {
public:
card();
int val = 0;
};
}
//deck.cpp
#include "deck.h"
using namespace deck_base;
card::card() {
val = 10;
};
When I try to compile the main.cpp file, I get the following error in console:
Starting build...
/usr/bin/g++ -fdiagnostics-color=always -std=c++11 -g /Users/######/vscode/blackjack/main.cpp -o /Users/######/vscode/blackjack/main
Undefined symbols for architecture arm64:
"deck_base::card::card()", referenced from:
_main in main-85016f.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Build finished with error(s).
I have tried just placing the code in the implementation file into the main file, which worked, but I would prefer importing as clutter will eventually become an issue continuing the project. I am using vs code for this, if that matters as well. None of the solutions to this problem that I have found on here or elsewhere on the internet seem to apply in this situation, or they didn't help.