Suppose I have a number of similar classes that contain some variables and some functions in common, call the classes B,C and D, and supposed they are all derived from a base class A. If I want to implement a method on them that prints something like "Hello, Im class B", "Hello, I'm class C", etc, then clearly I could achieve this by using a virtual class in A that has no definition and overriding the definition in each of my derived classes. What I want to know is if there is a way to exploit the fact that the functions are essentially performing the same task ie printing the same message, except for the fact that they are each printing their own class name, to save me from having to write the method separately in each derived class. ie to save me from doing this: void B::message() {cout<<"Hello, Im B";}, void C::message() {cout<< "Hello, I'm C";}, etc, which means writing the same code over and over.
I hope this question makes sense to someone. I'm quite new to C++ so would appreciate any help.