I copied the code form Document But can't build

I copied the following code and pasted it to the end of MyActor1.cpp,but the compiler tell me inherited member not allowed.
void AMyActor1::PostInitProperties()
{
Super::PostInitProperties();
DamagePerSecond = TotalDamage / DamageTimeInSeconds;
}

Does your header file have virtual void PostInitProperties() override; in it? If not, it will not compile. In C++, your header must contain the declaration while your .cpp file must contain the definition. Some people will point out that you can put the function in the header, but this is generally not recommended for non-template classes and/or non-inline functions.