I am learning C++ using Bjarne's book, everything was fine until I get to learn how to include header files.
My codes are as below:
my.h
#ifndef MY_H
#define MY_H
extern int foo;
void print_foo();
#endif
my.cpp
#include "my.h"
#include <iostream>
using namespace std;
void print_foo() {
cout << foo << endl;
}
use.cpp
#include "my.h"
int foo = 7;
int main() {
print_foo();
}
I put them under the same folder with no space in folder name, I opened a new window from VS code, then I ran user.cpp and get the error saying undefined reference to print_foo.
Did I miss some key steps using VS code? because I think the codes are correct.