You are passing Books
by value to func()
.
void func(Books x)
{
x.set_Data();
x.calcDiscountedPrice();
}
This strategy is known as pass by value. It just of copy not actual object.
You need to pass Books
by reference into func
. For more details please refer How to pass objects to functions in C++
solved How to return a value back to main using accessor and object with array