N
none
I have this class:
// header file
#ifndef A_H
#define A_H
class A {
public:
A();
};
#endif // A_H
// .cpp file
#ifndef A_CPP
#define A_CPP
#include "A.h"
A::A() {
}
#endif // A_CPP
When I create the class like:
A a;
I get the error:
undefined reference to `A::A()'
On solution to the problem is to include A.cpp at the end of A.h like:
// header file
#ifndef A_H
#define A_H
class A {
public:
A();
};
#include "A.cpp"
#endif // A_H
But is it good practice to include .cpp files at the end of .h file?
I have seen this done in various large CMake public projects like ITK but why is this convention used?
// header file
#ifndef A_H
#define A_H
class A {
public:
A();
};
#endif // A_H
// .cpp file
#ifndef A_CPP
#define A_CPP
#include "A.h"
A::A() {
}
#endif // A_CPP
When I create the class like:
A a;
I get the error:
undefined reference to `A::A()'
On solution to the problem is to include A.cpp at the end of A.h like:
// header file
#ifndef A_H
#define A_H
class A {
public:
A();
};
#include "A.cpp"
#endif // A_H
But is it good practice to include .cpp files at the end of .h file?
I have seen this done in various large CMake public projects like ITK but why is this convention used?