HC4*_*ica 4 c++ const decltype c++11
请考虑以下代码:
template <typename T>
class B
{
};
template <typename T>
B<T> f(T& t)
{
return B<T>();
}
class A
{
class C {};
C c;
public:
A() {}
decltype(f(c)) get_c() const { return f(c); }
};
int main()
{
A a;
a.get_c();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译它时,我收到错误:
test.cpp: In member function 'B<A::C> A::get_c() const':
test.cpp:31:46: error: conversion from 'B<const A::C>' to non-scalar type 'B<A::C>' requested
Run Code Online (Sandbox Code Playgroud)
它似乎在decltype,和编译器不知道这是一个const成员函数,因此c是类型的const C,并因此推断不正确的类型,f(c)是B<C>不是B<const C>这是它到底是什么.
我做错了什么,或者这是编译错误?我使用gcc 4.6,但4.4和4.5表现出相同的行为.
| 归档时间: |
|
| 查看次数: |
532 次 |
| 最近记录: |