小编jrr*_*ry7的帖子

关于C++ 0x引用崩溃的问题

我不知道为什么这些代码无法编译.我在Visual c + + 2010和gcc中测试了-std = c ++ 0x.有人提出一些建议吗?谢谢!

template<typename T>
class Foo
{
public:
 void test(const T&){cout<<"const";}
 void test(      T&){cout<<"non const";}
};

int main()
{
 int a;
 Foo<int&> f;
}
Run Code Online (Sandbox Code Playgroud)

编译错误:'void Foo :: test(T)':已定义或声明的成员函数

但为什么这可以编译?

template<typename T> void foo(const T&){cout<<"const"; }
template<typename T> void foo( T&){cout<<"non const"; }
int main()
 {
    int a; 
    foo<int&>(a);
 }
Run Code Online (Sandbox Code Playgroud)

我读过c ++ 0x文章说:T && == T&,所以const T && == const T&?

c++ c++11

5
推荐指数
2
解决办法
845
查看次数

如何获取c ++ 0x lambda表达式的类型?

我想得到lambda的类型作为模板参数.这该怎么做?

template<class T>
class Foo
{
public:
    Foo(T t){ t(); }
};

int main()
{   
    Foo< type?? > foo([](){ cout<<"construct OK"; });

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ lambda c++11

4
推荐指数
1
解决办法
575
查看次数

标签 统计

c++ ×2

c++11 ×2

lambda ×1