What should be return type of the member method of that struct which has a
double *p as the member
That would be lvalue reference to double, the type double&.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
#include <cassert>
struct a
{
double* px;
double& dereference() const { assert(px); return *px; }
};
int main()
{
double x;
a my_a {&x};
my_a.dereference() = 42.0;
std::cout << x << '\n';
}
Can a return type be both lvalue and rvalue?
"lvalue" does not mean "goes on left of the assignment operator" and "rvalue" does not mean "goes on right of the assignment operator". C++ uses a more nuanced definition.
The terms "lvalue" and "rvalue" are classes of expressions, not types. Therefore one major conceptual problem with this question is that a type does not have a value category at all.