So, I have a pretty simple project in VS2019 that includes three files:
a.h
#pragma once
class A {
public:
A();
};
a.cpp
class A {
public:
A() {}
};
main.cpp
#include <vector>
#include "a.h"
int main() {
std::vector<A> va;
va.emplace_back();
return 0;
}
It works fine without vectors. But this code throws an linker error about constructor. What I really don't understand is if I change a.cpp that way:
#include "a.h"
A::A() {}
it works fine. Why doesn't the linker see the constructor in the body of the class?