I'm getting a compiler error when I try to inline a method of one of my classes. It works when I take away the "inline" keyword.
Here's a simplified example:
main.cpp:
#include "my_class.h"
int main() {
MyClass c;
c.TestMethod();
return 0;
}
my_class.h:
class MyClass {
public:
void TestMethod();
};
my_class.cpp:
#include "my_class.h"
inline void MyClass::TestMethod() {
}
I try compiling with:
g++ main.cpp my_class.cpp
I get the error:
main.cpp:(.text+0xd): undefined reference to `MyClass::TestMethod()'
Everything is fine if I take away the "inline". What's causing this problem? (and how should I inline class methods? Is it possible?)
Thanks.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…