#include <iostream>
#include <ostream>
using namespace std;
enum Month
{
jan = 1,
feb,
mar
};
class Show
{
public:
virtual void Display() = 0;
};
class Date : public Show
{
private:
Month m;
int day;
int year;
public:
Date( Month mName, int dayName, int yearName )
{
m = mName;
day = dayName;
year = yearName;
}
void Display()
{
cout << this->m << endl;
}
};
void displayData( void *data[] )
{
Month m = *( reinterpret_cast<const Month*> ( data[ 0 ] ) );
cout << m << endl;
}
int main( int argc, char**argv )
{
Date d1( jan, 28, 2017 );
void * data[ 1 ];
data[ 0 ] = &d1;
displayData( data );
return 0;
}
I'm getting the correct value for Month m in the function void displayData but when I inherit the Date class from the abstract class Show, then I'm getting a garbage value for Month m. Can anyone tell me why is this happening ?