Hi all,
I had a very weird problem with precompile header. The linker generates LNK2019: unresolved external symbol error when I implement method in .cpp file. However, the program could be compiled if I implement method in .h file. I happened to find out a solution but I have no idea about the root cause of this error.
My project structure looks like this
Solution
->project 1
->project 2
Project 1 has 3 files. A.h, A.cpp and stdafx.h
file A.h
#pragma once
class A
{
public:
int num;
A();
};
file A.cpp
#include "stdafx.h"
A::A()
{
num = 2;
}
file stdafx.h
...
#include "A.h"
...
In project 2. I want to use A class.
file whatever.cpp
#include "stdafx.h"
#include "../Project1/A.h"
...
A* a_obj = new A();
...
In compile time, the linker reports unresolved external symbol error for the A construction function. If I implement the constructor in A.h file. the project2 could be successful complied. I want to know, why can not put the implementation in A.cpp file? What is the right way to organize precompile header?
Thank you