I have a problem providing the correct overloading for const and not const getter functions with the new return value syntax.
In my class PhysicalNode
I have defined a getter function with the new return value syntax. This is needed as the return type of the getter depends on the type of the member.
class PhysicalNode {
private:
solver::EnergySolver energySolver_; ///< The energy solver of this node
//solver::EnergyMomentumSolver energySolver_
public:
auto getEnergySolver()-> typename
std::add_lvalue_reference<decltype(PhysicalNode::energySolver_)>::type;
}
However I want now to also provide this method as const.
Normally I would use function overloading to define my const and not const getter function like that.
class PhysicalNode {
private:
solver::EnergySolver energySolver_;
public:
const solver::EnergySolver& getEnergySolver() const;
solver::EnergySolver& getEnergySolver();
}
I have tried the following function declaration but it does not work:
const auto getEnergySolver() const-> typename
std::add_lvalue_reference<decltype(PhysicalNode::energySolver_)>::type;
The compile error is:
PhysicalNode.cpp:72: error: invalid initialization of reference of type
'std::__add_lvalue_reference_helper<LbmLib::solver::EnergySolver, true,
false>::type {aka LbmLib::solver::EnergySolver&}' from expression of type
'const LbmLib::solver::EnergySolver'
How do I need to define the function declaration to define this function as constant.
typename
? IsPhysicalNode
a class template?