Consider the following code:
g++ gives the error:Code:template <typename T> class really_long_complicated_typename { public: really_long_complicated_typename(T& x) : x(x) {} private: T& x; }; template <typename T> really_long_complicated_typename<T> f(T& t) { return really_long_complicated_typename<T>(t); } class A { class C {}; C c; public: A() {} decltype(f(c)) get_c() const { return f(c); } }; int main() { const A a; a.get_c(); }
The problem is that the expression f(c) in the return statement is really_long_complicated_typename<const A::C>, but decltype doesn't "know" that this is a const member function, so decltype(f(c)) is deduced to be really_long_complicated_typename<A::C>.Code:test.cpp: In member function really_long_complicated_typename<A::C> A::get_c() const: test.cpp:24: error: conversion from really_long_complicated_typename<const A::C> to non-scalar type really_long_complicated_typename<A::C> requested
Is there a way around this?




Reply With Quote